This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][C++] Remove 99% calls to expr*location


This removes 99% of the calls to expr_has_location, expr_locus and
expr_location.  Currently the cp_walk_subtrees subroutine saves and
restores the input_location for every subtree visited (!) for the
appearant reason

-   /* Set input_location here so we get the right instantiation context
-      if we call instantiate_decl from inlinable_function_p.  */
-   save_locus = input_location;
-   if (EXPR_HAS_LOCATION (*tp))
-     input_location = EXPR_LOCATION (*tp);

but instantiate_decl is never called from the walk tree, but only from the
cannot_inline_tree_fn langhook.  inlinable_function_p looks like:

static bool
inlinable_function_p (tree fn)
{
...
  inlinable = !lang_hooks.tree_inlining.cannot_inline_tree_fn (&fn);
...
  else if (inline_forbidden_p (fn))
    {
...

where only inline_forbidden_p does a walk_tree.  I fail to see why
we should punish 99% of walk_tree just for this case, given that
instantiate_decl only writes to input_location as well.

Maybe someone remebers why this was necessary?  The following patch
get's all of expr_location stuff off the profiling radar (so no need
for me to optimize it, which can be done, too, see the 2nd patch after
the first one).

Ok after bootstrapping and regtesting??

Thanks,
Richard.

2007-03-29  Richard Guenther  <rguenther@suse.de>

	* tree.c (cp_walk_subtrees): Do not set input_location.

Index: cp/tree.c
===================================================================
*** cp/tree.c	(revision 123218)
--- cp/tree.c	(working copy)
*************** cp_walk_subtrees (tree *tp, int *walk_su
*** 2203,2209 ****
  		  void *data, struct pointer_set_t *pset)
  {
    enum tree_code code = TREE_CODE (*tp);
-   location_t save_locus;
    tree result;
  
  #define WALK_SUBTREE(NODE)				\
--- 2203,2208 ----
*************** cp_walk_subtrees (tree *tp, int *walk_su
*** 2214,2225 ****
      }							\
    while (0)
  
-   /* Set input_location here so we get the right instantiation context
-      if we call instantiate_decl from inlinable_function_p.  */
-   save_locus = input_location;
-   if (EXPR_HAS_LOCATION (*tp))
-     input_location = EXPR_LOCATION (*tp);
- 
    /* Not one of the easy cases.  We must explicitly go through the
       children.  */
    result = NULL_TREE;
--- 2213,2218 ----
*************** cp_walk_subtrees (tree *tp, int *walk_su
*** 2301,2313 ****
        break;
  
      default:
-       input_location = save_locus;
        return NULL_TREE;
      }
  
    /* We didn't find what we were looking for.  */
   out:
-   input_location = save_locus;
    return result;
  
  #undef WALK_SUBTREE
--- 2294,2304 ----



We have very interesting call patterns here.  For tramp3d the major
offender is cp_walk_subtrees calling expr_has_location which calls
expr_location.  But on the other hand expr_location calls expr_has_location
as well.  We can optimize the mess by inlining them into each other.

2007-03-29  Richard Guenther  <rguenther@suse.de>

	* tree.c (expr_location): Mark inline.
	(expr_locus): Likewise.
	(expr_has_location): Likewise.  Move below set_expr_locus.

Index: tree.c
===================================================================
*** tree.c	(revision 123218)
--- tree.c	(working copy)
*************** annotate_with_locus (tree node, location
*** 3410,3416 ****
  /* The source location of this expression.  Non-tree_exp nodes such as
     decls and constants can be shared among multiple locations, so
     return nothing.  */
! location_t
  expr_location (tree node)
  {
  #ifdef USE_MAPPED_LOCATION
--- 3410,3416 ----
  /* The source location of this expression.  Non-tree_exp nodes such as
     decls and constants can be shared among multiple locations, so
     return nothing.  */
! inline location_t
  expr_location (tree node)
  {
  #ifdef USE_MAPPED_LOCATION
*************** set_expr_location (tree node, location_t
*** 3438,3457 ****
  #endif
  }
  
- bool
- expr_has_location (tree node)
- {
- #ifdef USE_MAPPED_LOCATION
-   return expr_location (node) != UNKNOWN_LOCATION;
- #else
-   return expr_locus (node) != NULL;
- #endif
- }
- 
  #ifdef USE_MAPPED_LOCATION
! source_location *
  #else
! source_locus
  #endif
  expr_locus (tree node)
  {
--- 3438,3447 ----
  #endif
  }
  
  #ifdef USE_MAPPED_LOCATION
! inline source_location *
  #else
! inline source_locus
  #endif
  expr_locus (tree node)
  {
*************** set_expr_locus (tree node,
*** 3500,3505 ****
--- 3490,3505 ----
  #endif
  }
  
+ inline bool
+ expr_has_location (tree node)
+ {
+ #ifdef USE_MAPPED_LOCATION
+   return expr_location (node) != UNKNOWN_LOCATION;
+ #else
+   return expr_locus (node) != NULL;
+ #endif
+ }
+ 
  const char **
  expr_filename (tree node)
  {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]