referenced vars can contain things we won't expand and shouldn't be
used to drive codegen (well, my goal is still to drop referenced
vars and solely use local decls everywhere, eventually adding a way
to do the UID -> decl lookup there).

Bootstrapped and tested on x86_64-unknown-linux-gnu, installed.

Richard.

2012-07-20  Richard Guenther  <rguent...@suse.de>

        * tree-dfa.c (collect_dfa_stats): Simplify.
        * tree-ssa-structalias.c (compute_may_aliases): Do not dump
        referenced vars.
        * cfgexpand.c (estimated_stack_frame_size): Walk over local
        decls instead of referenced vars.
        * tree-ssa.c (delete_tree_ssa): Simplify.
        * tree-tailcall.c (find_tail_calls): Walk over local decls
        instead of referenced vars.
        (add_virtual_phis): Remove.
        (tree_optimize_tail_calls_1): Instead mark the virtual operand
        for renaming.

Index: gcc/tree-dfa.c
===================================================================
*** gcc/tree-dfa.c      (revision 189712)
--- gcc/tree-dfa.c      (working copy)
*************** static void
*** 371,377 ****
  collect_dfa_stats (struct dfa_stats_d *dfa_stats_p ATTRIBUTE_UNUSED)
  {
    basic_block bb;
-   referenced_var_iterator vi;
    tree var;
  
    gcc_assert (dfa_stats_p);
--- 341,346 ----
*************** collect_dfa_stats (struct dfa_stats_d *d
*** 379,387 ****
    memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d));
  
    /* Count all the variable annotations.  */
!   FOR_EACH_REFERENCED_VAR (cfun, var, vi)
!     if (var_ann (var))
!       dfa_stats_p->num_var_anns++;
  
    /* Walk all the statements in the function counting references.  */
    FOR_EACH_BB (bb)
--- 348,354 ----
    memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d));
  
    /* Count all the variable annotations.  */
!   dfa_stats_p->num_var_anns = htab_elements (gimple_referenced_vars (cfun));
  
    /* Walk all the statements in the function counting references.  */
    FOR_EACH_BB (bb)
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c  (revision 189712)
--- gcc/tree-ssa-structalias.c  (working copy)
*************** compute_may_aliases (void)
*** 6736,6744 ****
  
          /* But still dump what we have remaining it.  */
          dump_alias_info (dump_file);
- 
-         if (dump_flags & TDF_DETAILS)
-           dump_referenced_vars (dump_file);
        }
  
        return 0;
--- 6736,6741 ----
*************** compute_may_aliases (void)
*** 6751,6762 ****
  
    /* Debugging dumps.  */
    if (dump_file)
!     {
!       dump_alias_info (dump_file);
! 
!       if (dump_flags & TDF_DETAILS)
!       dump_referenced_vars (dump_file);
!     }
  
    /* Deallocate memory used by aliasing data structures and the internal
       points-to solution.  */
--- 6748,6754 ----
  
    /* Debugging dumps.  */
    if (dump_file)
!     dump_alias_info (dump_file);
  
    /* Deallocate memory used by aliasing data structures and the internal
       points-to solution.  */
Index: gcc/cfgexpand.c
===================================================================
*** gcc/cfgexpand.c     (revision 189712)
--- gcc/cfgexpand.c     (working copy)
*************** estimated_stack_frame_size (struct cgrap
*** 1420,1434 ****
    size_t i;
    tree var;
    tree old_cur_fun_decl = current_function_decl;
-   referenced_var_iterator rvi;
    struct function *fn = DECL_STRUCT_FUNCTION (node->symbol.decl);
  
    current_function_decl = node->symbol.decl;
    push_cfun (fn);
  
!   gcc_checking_assert (gimple_referenced_vars (fn));
!   FOR_EACH_REFERENCED_VAR (fn, var, rvi)
!     size += expand_one_var (var, true, false);
  
    if (stack_vars_num > 0)
      {
--- 1420,1433 ----
    size_t i;
    tree var;
    tree old_cur_fun_decl = current_function_decl;
    struct function *fn = DECL_STRUCT_FUNCTION (node->symbol.decl);
  
    current_function_decl = node->symbol.decl;
    push_cfun (fn);
  
!   FOR_EACH_LOCAL_DECL (fn, i, var)
!     if (auto_var_in_fn_p (var, fn->decl))
!       size += expand_one_var (var, true, false);
  
    if (stack_vars_num > 0)
      {
Index: gcc/tree-ssa.c
===================================================================
*** gcc/tree-ssa.c      (revision 189712)
--- gcc/tree-ssa.c      (working copy)
*************** delete_tree_ssa (void)
*** 1156,1168 ****
    /* Remove annotations from every referenced local variable.  */
    FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
      {
!       if (is_global_var (var))
!       continue;
!       if (var_ann (var))
!       {
!         ggc_free (var_ann (var));
!         *DECL_VAR_ANN_PTR (var) = NULL;
!       }
      }
    htab_delete (gimple_referenced_vars (cfun));
    cfun->gimple_df->referenced_vars = NULL;
--- 1156,1163 ----
    /* Remove annotations from every referenced local variable.  */
    FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
      {
!       ggc_free (var_ann (var));
!       *DECL_VAR_ANN_PTR (var) = NULL;
      }
    htab_delete (gimple_referenced_vars (cfun));
    cfun->gimple_df->referenced_vars = NULL;
Index: gcc/tree-tailcall.c
===================================================================
*** gcc/tree-tailcall.c (revision 189712)
--- gcc/tree-tailcall.c (working copy)
*************** find_tail_calls (basic_block bb, struct
*** 390,396 ****
    basic_block abb;
    size_t idx;
    tree var;
-   referenced_var_iterator rvi;
  
    if (!single_succ_p (bb))
      return;
--- 390,395 ----
*************** find_tail_calls (basic_block bb, struct
*** 484,490 ****
  
    /* Make sure the tail invocation of this function does not refer
       to local variables.  */
!   FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
      {
        if (TREE_CODE (var) != PARM_DECL
          && auto_var_in_fn_p (var, cfun->decl)
--- 483,489 ----
  
    /* Make sure the tail invocation of this function does not refer
       to local variables.  */
!   FOR_EACH_LOCAL_DECL (cfun, idx, var)
      {
        if (TREE_CODE (var) != PARM_DECL
          && auto_var_in_fn_p (var, cfun->decl)
*************** eliminate_tail_call (struct tailcall *t)
*** 872,907 ****
    release_defs (call);
  }
  
- /* Add phi nodes for the virtual operands defined in the function to the
-    header of the loop created by tail recursion elimination.
- 
-    Originally, we used to add phi nodes only for call clobbered variables,
-    as the value of the non-call clobbered ones obviously cannot be used
-    or changed within the recursive call.  However, the local variables
-    from multiple calls now share the same location, so the virtual ssa form
-    requires us to say that the location dies on further iterations of the 
loop,
-    which requires adding phi nodes.
- */
- static void
- add_virtual_phis (void)
- {
-   referenced_var_iterator rvi;
-   tree var;
- 
-   /* The problematic part is that there is no way how to know what
-      to put into phi nodes (there in fact does not have to be such
-      ssa name available).  A solution would be to have an artificial
-      use/kill for all virtual operands in EXIT node.  Unless we have
-      this, we cannot do much better than to rebuild the ssa form for
-      possibly affected virtual ssa names from scratch.  */
- 
-   FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
-     {
-       if (!is_gimple_reg (var) && gimple_default_def (cfun, var) != NULL_TREE)
-       mark_sym_for_renaming (var);
-     }
- }
- 
  /* Optimizes the tailcall described by T.  If OPT_TAILCALLS is true, also
     mark the tailcalls for the sibcall optimization.  */
  
--- 871,876 ----
*************** tree_optimize_tail_calls_1 (bool opt_tai
*** 1056,1063 ****
    if (changed)
      free_dominance_info (CDI_DOMINATORS);
  
    if (phis_constructed)
!     add_virtual_phis ();
    if (changed)
      return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals;
    return 0;
--- 1025,1036 ----
    if (changed)
      free_dominance_info (CDI_DOMINATORS);
  
+   /* Add phi nodes for the virtual operands defined in the function to the
+      header of the loop created by tail recursion elimination.  Do so
+      by triggering the SSA renamer.  */
    if (phis_constructed)
!     mark_sym_for_renaming (gimple_vop (cfun));
! 
    if (changed)
      return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals;
    return 0;

Reply via email to