RFA: Get rid of tree annotation

Richard Guenther richard.guenther@gmail.com
Mon Nov 23 17:10:00 GMT 2009


On Mon, Nov 23, 2009 at 5:46 PM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> When doing the whole expand-from-gimple thingy my ultimate goal was to get
> rid of the field tree_base.ann.  Unfortunately I wasn't completely ready
> for stage 3, and was left with CALL_EXPR which were still expanded as
> trees, which in turn use the common tree annotation for remembering the
> current statement in order to get profile information for builtin string
> expanders.
>
> I have most of the patch to expand also calls from gimple statement ready
> since some time, but the patch is (a) huge and (b) touches very old expand
> code (and (c) would need a new target hook to satisfy me completely).
> (a) is not so much a problem as much of the size is attributable to
> s/tree/gimple/ type of changes, so might be accepable also for stage 3.
> But (b) is a problem.  While I have it working for our architectures I
> don't think it's that acceptable for stage 3.
>
> But Richi still wanted to get rid of the common pointer in tree_base
> during stage 3, and I agree with him here.  Hence I added an intermediate
> solution, trading that pointer in all trees with a single global variable
> that stores the currently expanded gimple statement.
>
> So, this patch reduces the size of all trees except
> PARM_DECL, VAR_DECL, RESULT_DECL by one pointer.  We still need the var
> annotation during into-ssa and outof-ssa.
>
> I plan to submit the real patch, which then would get rid of the global
> variable (by rewriting builtins.c and calls.c to work on gimple
> statements) early during stage 1, once it opens.
>
> While reviewing keep in mind that also ann->lp_nr is unused.  Since some
> time already it never is set to anything, hence all the code connected
> with it is dead.
>
> Regstrapped on x86_64-linux (all langs+Ada), no regressions.  Okay for
> trunk?

Thanks for doing this.

+#define DECL_VAR_ANN_PTR(NODE) \
+  (TREE_CODE (NODE) == VAR_DECL ? &(NODE)->var_decl.ann \
+   : TREE_CODE (NODE) == PARM_DECL ? &(NODE)->parm_decl.ann \
+   : TREE_CODE (NODE) == RESULT_DECL ? &(NODE)->result_decl.ann \
+   : NULL)

if you'd have put the ann field into tree_decl_with_rtl you could
have avoided the above.  I doubt it would have made a big
difference - in fact only LABEL_DECLs and CONST_DECLs
would have an unused field that way.

So, any special reason you didn't go that way?

Thanks,
Richard.

>
> Ciao,
> Michael.
> --
>        * tree.h (union tree_ann_d): Don't declare.
>        (tree_base): Remove ann field.
>        (struct var_ann_d): Declare forward.
>        (tree_result_decl, tree_parm_decl, tree_var_decl): Add ann field.
>        (DECL_VAR_ANN_PTR): New macro.
>        * tree-dfa.c (create_var_ann): Rewrite in terms of above macro,
>        accept only VAR, PARM or RESULT decls.
>        (create_tree_common_ann): Remove.
>        (remove_referenced_var): Use DECL_VAR_ANN_PTR.
>        * tree-eh.c (lookup_expr_eh_lp): Remove.
>        * tree-flow-inline.h (var_ann, get_var_ann): Rewrite in terms of
>        DECL_VAR_ANN_PTR.
>        (ann_type, tree_common_ann, get_tree_common_ann): Remove.
>        * tree-flow.h (enum tree_ann_type): Remove.
>        (struct tree_ann_common_d): Remove.
>        (struct var_ann_d): Remove common field.
>        (union tree_ann_d): Remove.
>        (tree_ann_t, tree_ann_common_t): Remove typedefs.
>        (tree_common_ann, get_tree_common_ann, ann_type,
>        create_tree_common_ann, lookup_expr_eh_lp): Don't declare.
>        * tree-ssa.c (delete_tree_ssa): Use DECL_VAR_ANN_PTR.
>        * tree.c (copy_node_stat): Use DECL_VAR_ANN_PTR.
>        * builtins.c (expand_builtin_memcpy): Use
>        currently_expanding_gimple_stmt instead of tree annotation.
>        (expand_builtin_memset_args): Ditto.
>        * cfgexpand.c (currently_expanding_gimple_stmt): Add global variable.
>        (expand_call_stmt): Don't set tree annotation.
>        (expand_gimple_basic_block): Set currently_expanding_gimple_stmt.
>        * expr.c (expand_expr_real): Don't call lookup_expr_eh_lp.
>        * gimple.h (currently_expanding_gimple_stmt): Declare.
>
> Index: tree.h
> ===================================================================
> --- tree.h.orig 2009-11-23 15:41:34.000000000 +0100
> +++ tree.h      2009-11-23 15:53:41.000000000 +0100
> @@ -356,7 +356,6 @@ enum omp_clause_code
>
>    See the accessor macros, defined below, for documentation of the
>    fields.  */
> -union tree_ann_d;
>
>  struct GTY(()) tree_base {
>   ENUM_BITFIELD(tree_code) code : 16;
> @@ -398,8 +397,6 @@ struct GTY(()) tree_base {
>      in tree_base instead of tree_type is to save space.  The size of the
>      field must be large enough to hold addr_space_t values.  */
>   unsigned address_space : 8;
> -
> -  union tree_ann_d *ann;
>  };
>
>  struct GTY(()) tree_common {
> @@ -2854,8 +2851,10 @@ struct GTY(()) tree_label_decl {
>   int eh_landing_pad_nr;
>  };
>
> +struct var_ann_d;
>  struct GTY(()) tree_result_decl {
>   struct tree_decl_with_rtl common;
> +  struct var_ann_d *ann;
>  };
>
>  struct GTY(()) tree_const_decl {
> @@ -2873,6 +2872,7 @@ struct GTY(()) tree_const_decl {
>  struct GTY(()) tree_parm_decl {
>   struct tree_decl_with_rtl common;
>   rtx incoming_rtl;
> +  struct var_ann_d *ann;
>  };
>
>
> @@ -3082,8 +3082,15 @@ extern void decl_fini_priority_insert (t
>  #define DECL_THREAD_LOCAL_P(NODE) \
>   (VAR_DECL_CHECK (NODE)->decl_with_vis.tls_model >= TLS_MODEL_REAL)
>
> +#define DECL_VAR_ANN_PTR(NODE) \
> +  (TREE_CODE (NODE) == VAR_DECL ? &(NODE)->var_decl.ann \
> +   : TREE_CODE (NODE) == PARM_DECL ? &(NODE)->parm_decl.ann \
> +   : TREE_CODE (NODE) == RESULT_DECL ? &(NODE)->result_decl.ann \
> +   : NULL)
> +
>  struct GTY(()) tree_var_decl {
>   struct tree_decl_with_vis common;
> +  struct var_ann_d *ann;
>  };
>
>
> Index: tree-dfa.c
> ===================================================================
> --- tree-dfa.c.orig     2009-11-23 15:41:35.000000000 +0100
> +++ tree-dfa.c  2009-11-23 15:53:41.000000000 +0100
> @@ -133,12 +133,12 @@ create_var_ann (tree t)
>   var_ann_t ann;
>
>   gcc_assert (t);
> -  gcc_assert (DECL_P (t));
> -  gcc_assert (!t->base.ann || t->base.ann->common.type == VAR_ANN);
> +  gcc_assert (TREE_CODE (t) == VAR_DECL
> +             || TREE_CODE (t) == PARM_DECL
> +             || TREE_CODE (t) == RESULT_DECL);
>
>   ann = GGC_CNEW (struct var_ann_d);
> -  ann->common.type = VAR_ANN;
> -  t->base.ann = (tree_ann_t) ann;
> +  *DECL_VAR_ANN_PTR (t) = ann;
>
>   return ann;
>  }
> @@ -188,24 +188,6 @@ renumber_gimple_stmt_uids_in_blocks (bas
>     }
>  }
>
> -/* Create a new annotation for a tree T.  */
> -
> -tree_ann_common_t
> -create_tree_common_ann (tree t)
> -{
> -  tree_ann_common_t ann;
> -
> -  gcc_assert (t);
> -  gcc_assert (!t->base.ann || t->base.ann->common.type == TREE_ANN_COMMON);
> -
> -  ann = GGC_CNEW (struct tree_ann_common_d);
> -
> -  ann->type = TREE_ANN_COMMON;
> -  t->base.ann = (tree_ann_t) ann;
> -
> -  return ann;
> -}
> -
>  /* Build a temporary.  Make sure and register it to be renamed.  */
>
>  tree
> @@ -654,7 +636,7 @@ remove_referenced_var (tree var)
>       && (v_ann = var_ann (var)))
>     {
>       ggc_free (v_ann);
> -      var->base.ann = NULL;
> +      *DECL_VAR_ANN_PTR (var) = NULL;
>     }
>   gcc_assert (DECL_P (var));
>   in.uid = uid;
> Index: tree-eh.c
> ===================================================================
> --- tree-eh.c.orig      2009-11-23 15:38:08.000000000 +0100
> +++ tree-eh.c   2009-11-23 15:53:41.000000000 +0100
> @@ -203,21 +203,6 @@ lookup_stmt_eh_lp (gimple t)
>   return lookup_stmt_eh_lp_fn (cfun, t);
>  }
>
> -/* Likewise, but reference a tree expression instead.  */
> -
> -int
> -lookup_expr_eh_lp (tree t)
> -{
> -  if (cfun && cfun->eh->throw_stmt_table && t && EXPR_P (t))
> -    {
> -      tree_ann_common_t ann = tree_common_ann (t);
> -      if (ann)
> -       return ann->lp_nr;
> -    }
> -  return 0;
> -}
> -
> -
>  /* First pass of EH node decomposition.  Build up a tree of GIMPLE_TRY_FINALLY
>    nodes and LABEL_DECL nodes.  We will use this during the second phase to
>    determine if a goto leaves the body of a TRY_FINALLY_EXPR node.  */
> Index: tree-flow-inline.h
> ===================================================================
> --- tree-flow-inline.h.orig     2009-11-23 15:38:08.000000000 +0100
> +++ tree-flow-inline.h  2009-11-23 15:53:41.000000000 +0100
> @@ -152,15 +152,8 @@ fill_referenced_var_vec (VEC (tree, heap
>  static inline var_ann_t
>  var_ann (const_tree t)
>  {
> -  var_ann_t ann;
> -
> -  if (!t->base.ann)
> -    return NULL;
> -  ann = (var_ann_t) t->base.ann;
> -
> -  gcc_assert (ann->common.type == VAR_ANN);
> -
> -  return ann;
> +  const var_ann_t *p = DECL_VAR_ANN_PTR (t);
> +  return p ? *p : NULL;
>  }
>
>  /* Return the variable annotation for T, which must be a _DECL node.
> @@ -168,8 +161,9 @@ var_ann (const_tree t)
>  static inline var_ann_t
>  get_var_ann (tree var)
>  {
> -  var_ann_t ann = var_ann (var);
> -  return (ann) ? ann : create_var_ann (var);
> +  var_ann_t *p = DECL_VAR_ANN_PTR (var);
> +  gcc_assert (p);
> +  return *p ? *p : create_var_ann (var);
>  }
>
>  /* Get the number of the next statement uid to be allocated.  */
> @@ -193,13 +187,6 @@ inc_gimple_stmt_max_uid (struct function
>   return fn->last_stmt_uid++;
>  }
>
> -/* Return the annotation type for annotation ANN.  */
> -static inline enum tree_ann_type
> -ann_type (tree_ann_t ann)
> -{
> -  return ann->common.type;
> -}
> -
>  /* Return the line number for EXPR, or return -1 if we have no line
>    number information for it.  */
>  static inline int
> @@ -678,26 +665,6 @@ is_call_used (const_tree var)
>              && pt_solution_includes (&cfun->gimple_df->callused, var)));
>  }
>
> -/* Return the common annotation for T.  Return NULL if the annotation
> -   doesn't already exist.  */
> -static inline tree_ann_common_t
> -tree_common_ann (const_tree t)
> -{
> -  /* Watch out static variables with unshared annotations.  */
> -  if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
> -    return &var_ann (t)->common;
> -  return &t->base.ann->common;
> -}
> -
> -/* Return a common annotation for T.  Create the constant annotation if it
> -   doesn't exist.  */
> -static inline tree_ann_common_t
> -get_tree_common_ann (tree t)
> -{
> -  tree_ann_common_t ann = tree_common_ann (t);
> -  return (ann) ? ann : create_tree_common_ann (t);
> -}
> -
>  /*  -----------------------------------------------------------------------  */
>
>  /* The following set of routines are used to iterator over various type of
> Index: tree-flow.h
> ===================================================================
> --- tree-flow.h.orig    2009-11-23 15:38:08.000000000 +0100
> +++ tree-flow.h 2009-11-23 15:53:41.000000000 +0100
> @@ -125,24 +125,6 @@ struct GTY(()) ptr_info_def
>  };
>
>
> -/*---------------------------------------------------------------------------
> -                  Tree annotations stored in tree_base.ann
> ----------------------------------------------------------------------------*/
> -enum tree_ann_type { TREE_ANN_COMMON, VAR_ANN };
> -
> -struct GTY(()) tree_ann_common_d {
> -  /* Annotation type.  */
> -  enum tree_ann_type type;
> -
> -  /* Record EH landing pad number into a statement tree created
> -     during RTL expansion (see gimple_to_tree).  */
> -  int lp_nr;
> -
> -  /* Pointer to original GIMPLE statement.  Used during RTL expansion
> -     (see gimple_to_tree).  */
> -  gimple stmt;
> -};
> -
>  /* It is advantageous to avoid things like life analysis for variables which
>    do not need PHI nodes.  This enum describes whether or not a particular
>    variable may need a PHI node.  */
> @@ -192,8 +174,6 @@ enum noalias_state {
>
>
>  struct GTY(()) var_ann_d {
> -  struct tree_ann_common_d common;
> -
>   /* Used when building base variable structures in a var_map.  */
>   unsigned base_var_processed : 1;
>
> @@ -318,20 +298,10 @@ typedef struct immediate_use_iterator_d
>
>
>
> -union GTY((desc ("ann_type ((tree_ann_t)&%h)"))) tree_ann_d {
> -  struct tree_ann_common_d GTY((tag ("TREE_ANN_COMMON"))) common;
> -  struct var_ann_d GTY((tag ("VAR_ANN"))) vdecl;
> -};
> -
> -typedef union tree_ann_d *tree_ann_t;
>  typedef struct var_ann_d *var_ann_t;
> -typedef struct tree_ann_common_d *tree_ann_common_t;
>
> -static inline tree_ann_common_t tree_common_ann (const_tree);
> -static inline tree_ann_common_t get_tree_common_ann (tree);
>  static inline var_ann_t var_ann (const_tree);
>  static inline var_ann_t get_var_ann (tree);
> -static inline enum tree_ann_type ann_type (tree_ann_t);
>  static inline void update_stmt (gimple);
>  static inline int get_lineno (const_gimple);
>
> @@ -556,7 +526,6 @@ extern const char *op_symbol_code (enum
>  extern var_ann_t create_var_ann (tree);
>  extern void renumber_gimple_stmt_uids (void);
>  extern void renumber_gimple_stmt_uids_in_blocks (basic_block *, int);
> -extern tree_ann_common_t create_tree_common_ann (tree);
>  extern void dump_dfa_stats (FILE *);
>  extern void debug_dfa_stats (void);
>  extern void debug_referenced_vars (void);
> @@ -856,7 +825,6 @@ extern void add_stmt_to_eh_lp (gimple, i
>  extern bool remove_stmt_from_eh_lp (gimple);
>  extern bool remove_stmt_from_eh_lp_fn (struct function *, gimple);
>  extern int lookup_stmt_eh_lp_fn (struct function *, gimple);
> -extern int lookup_expr_eh_lp (tree);
>  extern int lookup_stmt_eh_lp (gimple);
>  extern bool maybe_clean_eh_stmt_fn (struct function *, gimple);
>  extern bool maybe_clean_eh_stmt (gimple);
> Index: tree-ssa.c
> ===================================================================
> --- tree-ssa.c.orig     2009-11-23 15:41:35.000000000 +0100
> +++ tree-ssa.c  2009-11-23 15:53:41.000000000 +0100
> @@ -1138,9 +1138,11 @@ delete_tree_ssa (void)
>     {
>       if (is_global_var (var))
>        continue;
> -      if (var->base.ann)
> -        ggc_free (var->base.ann);
> -      var->base.ann = NULL;
> +      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;
> Index: tree.c
> ===================================================================
> --- tree.c.orig 2009-11-23 15:41:34.000000000 +0100
> +++ tree.c      2009-11-23 15:53:41.000000000 +0100
> @@ -955,7 +955,8 @@ copy_node_stat (tree node MEM_STAT_DECL)
>   TREE_CHAIN (t) = 0;
>   TREE_ASM_WRITTEN (t) = 0;
>   TREE_VISITED (t) = 0;
> -  t->base.ann = 0;
> +  if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
> +    *DECL_VAR_ANN_PTR (t) = 0;
>
>   if (TREE_CODE_CLASS (code) == tcc_declaration)
>     {
> Index: builtins.c
> ===================================================================
> --- builtins.c.orig     2009-11-23 15:41:34.000000000 +0100
> +++ builtins.c  2009-11-23 16:03:43.000000000 +0100
> @@ -3259,7 +3259,6 @@ expand_builtin_memcpy (tree exp, rtx tar
>       rtx dest_mem, src_mem, dest_addr, len_rtx;
>       HOST_WIDE_INT expected_size = -1;
>       unsigned int expected_align = 0;
> -      tree_ann_common_t ann;
>
>       /* If DEST is not a pointer type, call the normal function.  */
>       if (dest_align == 0)
> @@ -3270,9 +3269,9 @@ expand_builtin_memcpy (tree exp, rtx tar
>       if (src_align == 0)
>        return NULL_RTX;
>
> -      ann = tree_common_ann (exp);
> -      if (ann)
> -        stringop_block_profile (ann->stmt, &expected_align, &expected_size);
> +      if (currently_expanding_gimple_stmt)
> +        stringop_block_profile (currently_expanding_gimple_stmt,
> +                               &expected_align, &expected_size);
>
>       if (expected_align < dest_align)
>        expected_align = dest_align;
> @@ -3737,7 +3736,6 @@ expand_builtin_memset_args (tree dest, t
>   rtx dest_mem, dest_addr, len_rtx;
>   HOST_WIDE_INT expected_size = -1;
>   unsigned int expected_align = 0;
> -  tree_ann_common_t ann;
>
>   dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
>
> @@ -3745,9 +3743,9 @@ expand_builtin_memset_args (tree dest, t
>   if (dest_align == 0)
>     return NULL_RTX;
>
> -  ann = tree_common_ann (orig_exp);
> -  if (ann)
> -    stringop_block_profile (ann->stmt, &expected_align, &expected_size);
> +  if (currently_expanding_gimple_stmt)
> +    stringop_block_profile (currently_expanding_gimple_stmt,
> +                           &expected_align, &expected_size);
>
>   if (expected_align < dest_align)
>     expected_align = dest_align;
> Index: cfgexpand.c
> ===================================================================
> --- cfgexpand.c.orig    2009-11-23 15:41:35.000000000 +0100
> +++ cfgexpand.c 2009-11-23 16:25:22.000000000 +0100
> @@ -49,6 +49,10 @@ along with GCC; see the file COPYING3.
>    into RTL.  */
>  struct ssaexpand SA;
>
> +/* This variable holds the currently expanded gimple statement for purposes
> +   of comminucating the profile info to the builtin expanders.  */
> +gimple currently_expanding_gimple_stmt;
> +
>  /* Return an expression tree corresponding to the RHS of GIMPLE
>    statement STMT.  */
>
> @@ -1756,7 +1760,6 @@ expand_call_stmt (gimple stmt)
>  {
>   tree exp;
>   tree lhs = gimple_call_lhs (stmt);
> -  tree fndecl = gimple_call_fndecl (stmt);
>   size_t i;
>
>   exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
> @@ -1782,15 +1785,6 @@ expand_call_stmt (gimple stmt)
>   SET_EXPR_LOCATION (exp, gimple_location (stmt));
>   TREE_BLOCK (exp) = gimple_block (stmt);
>
> -  /* Record the original call statement, as it may be used
> -     to retrieve profile information during expansion.  */
> -
> -  if (fndecl && DECL_BUILT_IN (fndecl))
> -    {
> -      tree_ann_common_t ann = get_tree_common_ann (exp);
> -      ann->stmt = stmt;
> -    }
> -
>   if (lhs)
>     expand_assignment (lhs, exp, false);
>   else
> @@ -3106,6 +3100,7 @@ expand_gimple_basic_block (basic_block b
>       basic_block new_bb;
>
>       stmt = gsi_stmt (gsi);
> +      currently_expanding_gimple_stmt = stmt;
>
>       /* Expand this statement, then evaluate the resulting RTL and
>         fixup the CFG accordingly.  */
> @@ -3203,6 +3198,8 @@ expand_gimple_basic_block (basic_block b
>        }
>     }
>
> +  currently_expanding_gimple_stmt = NULL;
> +
>   /* Expand implicit goto and convert goto_locus.  */
>   FOR_EACH_EDGE (e, ei, bb->succs)
>     {
> Index: expr.c
> ===================================================================
> --- expr.c.orig 2009-11-23 15:38:08.000000000 +0100
> +++ expr.c      2009-11-23 16:06:55.000000000 +0100
> @@ -7157,8 +7157,7 @@ rtx
>  expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
>                  enum expand_modifier modifier, rtx *alt_rtl)
>  {
> -  int lp_nr = 0;
> -  rtx ret, last = NULL;
> +  rtx ret;
>
>   /* Handle ERROR_MARK before anybody tries to access its type.  */
>   if (TREE_CODE (exp) == ERROR_MARK
> @@ -7168,13 +7167,6 @@ expand_expr_real (tree exp, rtx target,
>       return ret ? ret : const0_rtx;
>     }
>
> -  if (flag_non_call_exceptions)
> -    {
> -      lp_nr = lookup_expr_eh_lp (exp);
> -      if (lp_nr)
> -       last = get_last_insn ();
> -    }
> -
>   /* If this is an expression of some kind and it has an associated line
>      number, then emit the line number before expanding the expression.
>
> @@ -7201,25 +7193,6 @@ expand_expr_real (tree exp, rtx target,
>       ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
>     }
>
> -  /* If using non-call exceptions, mark all insns that may trap.
> -     expand_call() will mark CALL_INSNs before we get to this code,
> -     but it doesn't handle libcalls, and these may trap.  */
> -  if (lp_nr)
> -    {
> -      rtx insn;
> -      for (insn = next_real_insn (last); insn;
> -          insn = next_real_insn (insn))
> -       {
> -         if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
> -             /* If we want exceptions for non-call insns, any
> -                may_trap_p instruction may throw.  */
> -             && GET_CODE (PATTERN (insn)) != CLOBBER
> -             && GET_CODE (PATTERN (insn)) != USE
> -             && insn_could_throw_p (insn))
> -           make_reg_eh_region_note (insn, 0, lp_nr);
> -       }
> -    }
> -
>   return ret;
>  }
>
> Index: gimple.h
> ===================================================================
> --- gimple.h.orig       2009-11-23 15:41:35.000000000 +0100
> +++ gimple.h    2009-11-23 16:02:24.000000000 +0100
> @@ -769,6 +769,10 @@ extern size_t const gimple_ops_offset_[]
>  /* Map GIMPLE codes to GSS codes.  */
>  extern enum gimple_statement_structure_enum const gss_for_code_[];
>
> +/* This variable holds the currently expanded gimple statement for purposes
> +   of comminucating the profile info to the builtin expanders.  */
> +extern gimple currently_expanding_gimple_stmt;
> +
>  gimple gimple_build_return (tree);
>
>  gimple gimple_build_assign_stat (tree, tree MEM_STAT_DECL);
>



More information about the Gcc-patches mailing list