tree, c++: declare some basic functions inline

Message ID 20221205042101.4144757-1-ppalka@redhat.com
State New
Headers
Series tree, c++: declare some basic functions inline |

Commit Message

Patrick Palka Dec. 5, 2022, 4:21 a.m. UTC
  The functions strip_array_types, is_typedef_decl, typedef_variant_p,
cp_type_quals and cp_expr_location are used throughout the C++ frontend
including in some fairly hot parts (e.g. in the tsubst routines and
cp_walk_subtree) and they're small enough that the overhead of calling
them out-of-line is relatively significant.

This patch moves their definitions into the appropriate headers to
enable inlining them.  This speeds up the C++ frontend by ~1% according
to my experiments.  In passing this also downgrades the assert in
cp_type_quals to a checking assert.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk stage3 or perhaps for stage1?

gcc/cp/ChangeLog:

	* cp-tree.h (cp_type_quals): Define here.  Downgrade assert into
	a checking assert.
	(cp_expr_location): Define here.
	* tree.cc (cp_expr_location): Don't define here.
	* typeck.cc (cp_type_quals): Don't define here.

gcc/ChangeLog:

	* tree.cc (strip_array_types): Don't define here.
	(is_typedef_decl): Don't define here.
	(typedef_variant_p): Don't define here.
	* tree.h (strip_array_types): Define here.
	(is_typedef_decl): Define here.
	(typedef_variant_p): Define here.
---
 gcc/cp/cp-tree.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
 gcc/cp/tree.cc   | 24 -----------------------
 gcc/cp/typeck.cc | 23 ----------------------
 gcc/tree.cc      | 29 ----------------------------
 gcc/tree.h       | 32 ++++++++++++++++++++++++++++---
 5 files changed, 77 insertions(+), 81 deletions(-)
  

Comments

Patrick Palka April 21, 2023, 5:07 p.m. UTC | #1
On Sun, 4 Dec 2022, Patrick Palka wrote:

> The functions strip_array_types, is_typedef_decl, typedef_variant_p,
> cp_type_quals and cp_expr_location are used throughout the C++ frontend
> including in some fairly hot parts (e.g. in the tsubst routines and
> cp_walk_subtree) and they're small enough that the overhead of calling
> them out-of-line is relatively significant.
> 
> This patch moves their definitions into the appropriate headers to
> enable inlining them.  This speeds up the C++ frontend by ~1% according
> to my experiments.  In passing this also downgrades the assert in
> cp_type_quals to a checking assert.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> for trunk stage3 or perhaps for stage1?

Ping.

> 
> gcc/cp/ChangeLog:
> 
> 	* cp-tree.h (cp_type_quals): Define here.  Downgrade assert into
> 	a checking assert.
> 	(cp_expr_location): Define here.
> 	* tree.cc (cp_expr_location): Don't define here.
> 	* typeck.cc (cp_type_quals): Don't define here.
> 
> gcc/ChangeLog:
> 
> 	* tree.cc (strip_array_types): Don't define here.
> 	(is_typedef_decl): Don't define here.
> 	(typedef_variant_p): Don't define here.
> 	* tree.h (strip_array_types): Define here.
> 	(is_typedef_decl): Define here.
> 	(typedef_variant_p): Define here.
> ---
>  gcc/cp/cp-tree.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
>  gcc/cp/tree.cc   | 24 -----------------------
>  gcc/cp/typeck.cc | 23 ----------------------
>  gcc/tree.cc      | 29 ----------------------------
>  gcc/tree.h       | 32 ++++++++++++++++++++++++++++---
>  5 files changed, 77 insertions(+), 81 deletions(-)
> 
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index addd26ea077..19914d08a03 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -49,7 +49,7 @@ c-common.h, not after.
>     but not all node kinds do (e.g. constants, and references to
>     params, locals, etc), so we stash a copy here.  */
>  
> -extern location_t cp_expr_location		(const_tree);
> +inline location_t cp_expr_location		(const_tree);
>  
>  class cp_expr
>  {
> @@ -8100,7 +8100,6 @@ extern bool error_type_p			(const_tree);
>  extern bool ptr_reasonably_similar		(const_tree, const_tree);
>  extern tree build_ptrmemfunc			(tree, tree, int, bool,
>  						 tsubst_flags_t);
> -extern int cp_type_quals			(const_tree);
>  extern int type_memfn_quals			(const_tree);
>  extern cp_ref_qualifier type_memfn_rqual	(const_tree);
>  extern tree apply_memfn_quals			(tree, cp_cv_quals,
> @@ -8151,6 +8150,29 @@ extern void maybe_warn_about_useless_cast       (location_t, tree, tree,
>  						 tsubst_flags_t);
>  extern tree cp_perform_integral_promotions      (tree, tsubst_flags_t);
>  
> +/* Returns the type qualifiers for this type, including the qualifiers on the
> +   elements for an array type.  */
> +
> +inline int
> +cp_type_quals (const_tree type)
> +{
> +  int quals;
> +  /* This CONST_CAST is okay because strip_array_types returns its
> +     argument unmodified and we assign it to a const_tree.  */
> +  type = strip_array_types (CONST_CAST_TREE (type));
> +  if (type == error_mark_node
> +      /* Quals on a FUNCTION_TYPE are memfn quals.  */
> +      || TREE_CODE (type) == FUNCTION_TYPE)
> +    return TYPE_UNQUALIFIED;
> +  quals = TYPE_QUALS (type);
> +  /* METHOD and REFERENCE_TYPEs should never have quals.  */
> +  gcc_checking_assert ((TREE_CODE (type) != METHOD_TYPE
> +			&& !TYPE_REF_P (type))
> +		       || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
> +			   == TYPE_UNQUALIFIED));
> +  return quals;
> +}
> +
>  extern tree finish_left_unary_fold_expr      (tree, int);
>  extern tree finish_right_unary_fold_expr     (tree, int);
>  extern tree finish_binary_fold_expr          (tree, tree, int);
> @@ -8168,6 +8190,30 @@ loc_or_input_loc (location_t loc)
>    return loc == UNKNOWN_LOCATION ? input_location : loc;
>  }
>  
> +/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
> +   locations.  */
> +
> +inline location_t
> +cp_expr_location (const_tree t_)
> +{
> +  tree t = CONST_CAST_TREE (t_);
> +  if (t == NULL_TREE)
> +    return UNKNOWN_LOCATION;
> +  switch (TREE_CODE (t))
> +    {
> +    case LAMBDA_EXPR:
> +      return LAMBDA_EXPR_LOCATION (t);
> +    case STATIC_ASSERT:
> +      return STATIC_ASSERT_SOURCE_LOCATION (t);
> +    case TRAIT_EXPR:
> +      return TRAIT_EXPR_LOCATION (t);
> +    case PTRMEM_CST:
> +      return PTRMEM_CST_LOCATION (t);
> +    default:
> +      return EXPR_LOCATION (t);
> +    }
> +}
> +
>  inline location_t
>  cp_expr_loc_or_loc (const_tree t, location_t or_loc)
>  {
> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
> index 1487f4975c5..4066b014f6e 100644
> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc
> @@ -6214,30 +6214,6 @@ cp_tree_code_length (enum tree_code code)
>      }
>  }
>  
> -/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
> -   locations.  */
> -
> -location_t
> -cp_expr_location (const_tree t_)
> -{
> -  tree t = CONST_CAST_TREE (t_);
> -  if (t == NULL_TREE)
> -    return UNKNOWN_LOCATION;
> -  switch (TREE_CODE (t))
> -    {
> -    case LAMBDA_EXPR:
> -      return LAMBDA_EXPR_LOCATION (t);
> -    case STATIC_ASSERT:
> -      return STATIC_ASSERT_SOURCE_LOCATION (t);
> -    case TRAIT_EXPR:
> -      return TRAIT_EXPR_LOCATION (t);
> -    case PTRMEM_CST:
> -      return PTRMEM_CST_LOCATION (t);
> -    default:
> -      return EXPR_LOCATION (t);
> -    }
> -}
> -
>  /* Implement -Wzero_as_null_pointer_constant.  Return true if the
>     conditions for the warning hold, false otherwise.  */
>  bool
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index 7dfe5acc67e..10b7ed020f7 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -11460,29 +11460,6 @@ comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
>      }
>  }
>  
> -/* Returns the type qualifiers for this type, including the qualifiers on the
> -   elements for an array type.  */
> -
> -int
> -cp_type_quals (const_tree type)
> -{
> -  int quals;
> -  /* This CONST_CAST is okay because strip_array_types returns its
> -     argument unmodified and we assign it to a const_tree.  */
> -  type = strip_array_types (CONST_CAST_TREE (type));
> -  if (type == error_mark_node
> -      /* Quals on a FUNCTION_TYPE are memfn quals.  */
> -      || TREE_CODE (type) == FUNCTION_TYPE)
> -    return TYPE_UNQUALIFIED;
> -  quals = TYPE_QUALS (type);
> -  /* METHOD and REFERENCE_TYPEs should never have quals.  */
> -  gcc_assert ((TREE_CODE (type) != METHOD_TYPE
> -	       && !TYPE_REF_P (type))
> -	      || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
> -		  == TYPE_UNQUALIFIED));
> -  return quals;
> -}
> -
>  /* Returns the function-ref-qualifier for TYPE */
>  
>  cp_ref_qualifier
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index 254b2373dcf..5eb6a49da31 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -7253,18 +7253,6 @@ build_array_type_nelts (tree elt_type, poly_uint64 nelts)
>    return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
>  }
>  
> -/* Recursively examines the array elements of TYPE, until a non-array
> -   element type is found.  */
> -
> -tree
> -strip_array_types (tree type)
> -{
> -  while (TREE_CODE (type) == ARRAY_TYPE)
> -    type = TREE_TYPE (type);
> -
> -  return type;
> -}
> -
>  /* Computes the canonical argument types from the argument type list
>     ARGTYPES.
>  
> @@ -12132,23 +12120,6 @@ get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
>      }
>  }
>  
> -/* Returns true if X is a typedef decl.  */
> -
> -bool
> -is_typedef_decl (const_tree x)
> -{
> -  return (x && TREE_CODE (x) == TYPE_DECL
> -          && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
> -}
> -
> -/* Returns true iff TYPE is a type variant created for a typedef. */
> -
> -bool
> -typedef_variant_p (const_tree type)
> -{
> -  return is_typedef_decl (TYPE_NAME (type));
> -}
> -
>  /* PR 84195: Replace control characters in "unescaped" with their
>     escaped equivalents.  Allow newlines if -fmessage-length has
>     been set to a non-zero value.  This is done here, rather than
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 4a19de1c94d..27001a4dfda 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -4807,9 +4807,20 @@ tree_to_poly_uint64 (const_tree t)
>  extern int tree_int_cst_sgn (const_tree);
>  extern int tree_int_cst_sign_bit (const_tree);
>  extern unsigned int tree_int_cst_min_precision (tree, signop);
> -extern tree strip_array_types (tree);
>  extern tree excess_precision_type (tree);
>  
> +/* Recursively examines the array elements of TYPE, until a non-array
> +   element type is found.  */
> +
> +inline tree
> +strip_array_types (tree type)
> +{
> +  while (TREE_CODE (type) == ARRAY_TYPE)
> +    type = TREE_TYPE (type);
> +
> +  return type;
> +}
> +
>  /* Desription of the reason why the argument of valid_constant_size_p
>     is not a valid size.  */
>  enum cst_size_error {
> @@ -5360,8 +5371,6 @@ extern tree create_artificial_label (location_t);
>  extern const char *get_name (tree);
>  extern bool stdarg_p (const_tree);
>  extern bool prototype_p (const_tree);
> -extern bool is_typedef_decl (const_tree x);
> -extern bool typedef_variant_p (const_tree);
>  extern bool auto_var_p (const_tree);
>  extern bool auto_var_in_fn_p (const_tree, const_tree);
>  extern tree build_low_bits_mask (tree, unsigned);
> @@ -5376,6 +5385,23 @@ extern void error_unavailable_use (tree, tree);
>  extern tree cache_integer_cst (tree, bool might_duplicate = false);
>  extern const char *combined_fn_name (combined_fn);
>  
> +/* Returns true if X is a typedef decl.  */
> +
> +inline bool
> +is_typedef_decl (const_tree x)
> +{
> +  return (x && TREE_CODE (x) == TYPE_DECL
> +	  && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
> +}
> +
> +/* Returns true iff TYPE is a type variant created for a typedef. */
> +
> +inline bool
> +typedef_variant_p (const_tree type)
> +{
> +  return is_typedef_decl (TYPE_NAME (type));
> +}
> +
>  /* Compare and hash for any structure which begins with a canonical
>     pointer.  Assumes all pointers are interchangeable, which is sort
>     of already assumed by gcc elsewhere IIRC.  */
> -- 
> 2.39.0.rc0.49.g083e01275b
> 
>
  
Jason Merrill April 21, 2023, 7:28 p.m. UTC | #2
On 4/21/23 13:07, Patrick Palka wrote:
> On Sun, 4 Dec 2022, Patrick Palka wrote:
> 
>> The functions strip_array_types, is_typedef_decl, typedef_variant_p,
>> cp_type_quals and cp_expr_location are used throughout the C++ frontend
>> including in some fairly hot parts (e.g. in the tsubst routines and
>> cp_walk_subtree) and they're small enough that the overhead of calling
>> them out-of-line is relatively significant.
>>
>> This patch moves their definitions into the appropriate headers to
>> enable inlining them.  This speeds up the C++ frontend by ~1% according
>> to my experiments.  In passing this also downgrades the assert in
>> cp_type_quals to a checking assert.
>>
>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
>> for trunk stage3 or perhaps for stage1?
> 
> Ping.

OK.

>>
>> gcc/cp/ChangeLog:
>>
>> 	* cp-tree.h (cp_type_quals): Define here.  Downgrade assert into
>> 	a checking assert.
>> 	(cp_expr_location): Define here.
>> 	* tree.cc (cp_expr_location): Don't define here.
>> 	* typeck.cc (cp_type_quals): Don't define here.
>>
>> gcc/ChangeLog:
>>
>> 	* tree.cc (strip_array_types): Don't define here.
>> 	(is_typedef_decl): Don't define here.
>> 	(typedef_variant_p): Don't define here.
>> 	* tree.h (strip_array_types): Define here.
>> 	(is_typedef_decl): Define here.
>> 	(typedef_variant_p): Define here.
>> ---
>>   gcc/cp/cp-tree.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
>>   gcc/cp/tree.cc   | 24 -----------------------
>>   gcc/cp/typeck.cc | 23 ----------------------
>>   gcc/tree.cc      | 29 ----------------------------
>>   gcc/tree.h       | 32 ++++++++++++++++++++++++++++---
>>   5 files changed, 77 insertions(+), 81 deletions(-)
>>
>> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
>> index addd26ea077..19914d08a03 100644
>> --- a/gcc/cp/cp-tree.h
>> +++ b/gcc/cp/cp-tree.h
>> @@ -49,7 +49,7 @@ c-common.h, not after.
>>      but not all node kinds do (e.g. constants, and references to
>>      params, locals, etc), so we stash a copy here.  */
>>   
>> -extern location_t cp_expr_location		(const_tree);
>> +inline location_t cp_expr_location		(const_tree);
>>   
>>   class cp_expr
>>   {
>> @@ -8100,7 +8100,6 @@ extern bool error_type_p			(const_tree);
>>   extern bool ptr_reasonably_similar		(const_tree, const_tree);
>>   extern tree build_ptrmemfunc			(tree, tree, int, bool,
>>   						 tsubst_flags_t);
>> -extern int cp_type_quals			(const_tree);
>>   extern int type_memfn_quals			(const_tree);
>>   extern cp_ref_qualifier type_memfn_rqual	(const_tree);
>>   extern tree apply_memfn_quals			(tree, cp_cv_quals,
>> @@ -8151,6 +8150,29 @@ extern void maybe_warn_about_useless_cast       (location_t, tree, tree,
>>   						 tsubst_flags_t);
>>   extern tree cp_perform_integral_promotions      (tree, tsubst_flags_t);
>>   
>> +/* Returns the type qualifiers for this type, including the qualifiers on the
>> +   elements for an array type.  */
>> +
>> +inline int
>> +cp_type_quals (const_tree type)
>> +{
>> +  int quals;
>> +  /* This CONST_CAST is okay because strip_array_types returns its
>> +     argument unmodified and we assign it to a const_tree.  */
>> +  type = strip_array_types (CONST_CAST_TREE (type));
>> +  if (type == error_mark_node
>> +      /* Quals on a FUNCTION_TYPE are memfn quals.  */
>> +      || TREE_CODE (type) == FUNCTION_TYPE)
>> +    return TYPE_UNQUALIFIED;
>> +  quals = TYPE_QUALS (type);
>> +  /* METHOD and REFERENCE_TYPEs should never have quals.  */
>> +  gcc_checking_assert ((TREE_CODE (type) != METHOD_TYPE
>> +			&& !TYPE_REF_P (type))
>> +		       || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
>> +			   == TYPE_UNQUALIFIED));
>> +  return quals;
>> +}
>> +
>>   extern tree finish_left_unary_fold_expr      (tree, int);
>>   extern tree finish_right_unary_fold_expr     (tree, int);
>>   extern tree finish_binary_fold_expr          (tree, tree, int);
>> @@ -8168,6 +8190,30 @@ loc_or_input_loc (location_t loc)
>>     return loc == UNKNOWN_LOCATION ? input_location : loc;
>>   }
>>   
>> +/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
>> +   locations.  */
>> +
>> +inline location_t
>> +cp_expr_location (const_tree t_)
>> +{
>> +  tree t = CONST_CAST_TREE (t_);
>> +  if (t == NULL_TREE)
>> +    return UNKNOWN_LOCATION;
>> +  switch (TREE_CODE (t))
>> +    {
>> +    case LAMBDA_EXPR:
>> +      return LAMBDA_EXPR_LOCATION (t);
>> +    case STATIC_ASSERT:
>> +      return STATIC_ASSERT_SOURCE_LOCATION (t);
>> +    case TRAIT_EXPR:
>> +      return TRAIT_EXPR_LOCATION (t);
>> +    case PTRMEM_CST:
>> +      return PTRMEM_CST_LOCATION (t);
>> +    default:
>> +      return EXPR_LOCATION (t);
>> +    }
>> +}
>> +
>>   inline location_t
>>   cp_expr_loc_or_loc (const_tree t, location_t or_loc)
>>   {
>> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
>> index 1487f4975c5..4066b014f6e 100644
>> --- a/gcc/cp/tree.cc
>> +++ b/gcc/cp/tree.cc
>> @@ -6214,30 +6214,6 @@ cp_tree_code_length (enum tree_code code)
>>       }
>>   }
>>   
>> -/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
>> -   locations.  */
>> -
>> -location_t
>> -cp_expr_location (const_tree t_)
>> -{
>> -  tree t = CONST_CAST_TREE (t_);
>> -  if (t == NULL_TREE)
>> -    return UNKNOWN_LOCATION;
>> -  switch (TREE_CODE (t))
>> -    {
>> -    case LAMBDA_EXPR:
>> -      return LAMBDA_EXPR_LOCATION (t);
>> -    case STATIC_ASSERT:
>> -      return STATIC_ASSERT_SOURCE_LOCATION (t);
>> -    case TRAIT_EXPR:
>> -      return TRAIT_EXPR_LOCATION (t);
>> -    case PTRMEM_CST:
>> -      return PTRMEM_CST_LOCATION (t);
>> -    default:
>> -      return EXPR_LOCATION (t);
>> -    }
>> -}
>> -
>>   /* Implement -Wzero_as_null_pointer_constant.  Return true if the
>>      conditions for the warning hold, false otherwise.  */
>>   bool
>> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
>> index 7dfe5acc67e..10b7ed020f7 100644
>> --- a/gcc/cp/typeck.cc
>> +++ b/gcc/cp/typeck.cc
>> @@ -11460,29 +11460,6 @@ comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
>>       }
>>   }
>>   
>> -/* Returns the type qualifiers for this type, including the qualifiers on the
>> -   elements for an array type.  */
>> -
>> -int
>> -cp_type_quals (const_tree type)
>> -{
>> -  int quals;
>> -  /* This CONST_CAST is okay because strip_array_types returns its
>> -     argument unmodified and we assign it to a const_tree.  */
>> -  type = strip_array_types (CONST_CAST_TREE (type));
>> -  if (type == error_mark_node
>> -      /* Quals on a FUNCTION_TYPE are memfn quals.  */
>> -      || TREE_CODE (type) == FUNCTION_TYPE)
>> -    return TYPE_UNQUALIFIED;
>> -  quals = TYPE_QUALS (type);
>> -  /* METHOD and REFERENCE_TYPEs should never have quals.  */
>> -  gcc_assert ((TREE_CODE (type) != METHOD_TYPE
>> -	       && !TYPE_REF_P (type))
>> -	      || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
>> -		  == TYPE_UNQUALIFIED));
>> -  return quals;
>> -}
>> -
>>   /* Returns the function-ref-qualifier for TYPE */
>>   
>>   cp_ref_qualifier
>> diff --git a/gcc/tree.cc b/gcc/tree.cc
>> index 254b2373dcf..5eb6a49da31 100644
>> --- a/gcc/tree.cc
>> +++ b/gcc/tree.cc
>> @@ -7253,18 +7253,6 @@ build_array_type_nelts (tree elt_type, poly_uint64 nelts)
>>     return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
>>   }
>>   
>> -/* Recursively examines the array elements of TYPE, until a non-array
>> -   element type is found.  */
>> -
>> -tree
>> -strip_array_types (tree type)
>> -{
>> -  while (TREE_CODE (type) == ARRAY_TYPE)
>> -    type = TREE_TYPE (type);
>> -
>> -  return type;
>> -}
>> -
>>   /* Computes the canonical argument types from the argument type list
>>      ARGTYPES.
>>   
>> @@ -12132,23 +12120,6 @@ get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
>>       }
>>   }
>>   
>> -/* Returns true if X is a typedef decl.  */
>> -
>> -bool
>> -is_typedef_decl (const_tree x)
>> -{
>> -  return (x && TREE_CODE (x) == TYPE_DECL
>> -          && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
>> -}
>> -
>> -/* Returns true iff TYPE is a type variant created for a typedef. */
>> -
>> -bool
>> -typedef_variant_p (const_tree type)
>> -{
>> -  return is_typedef_decl (TYPE_NAME (type));
>> -}
>> -
>>   /* PR 84195: Replace control characters in "unescaped" with their
>>      escaped equivalents.  Allow newlines if -fmessage-length has
>>      been set to a non-zero value.  This is done here, rather than
>> diff --git a/gcc/tree.h b/gcc/tree.h
>> index 4a19de1c94d..27001a4dfda 100644
>> --- a/gcc/tree.h
>> +++ b/gcc/tree.h
>> @@ -4807,9 +4807,20 @@ tree_to_poly_uint64 (const_tree t)
>>   extern int tree_int_cst_sgn (const_tree);
>>   extern int tree_int_cst_sign_bit (const_tree);
>>   extern unsigned int tree_int_cst_min_precision (tree, signop);
>> -extern tree strip_array_types (tree);
>>   extern tree excess_precision_type (tree);
>>   
>> +/* Recursively examines the array elements of TYPE, until a non-array
>> +   element type is found.  */
>> +
>> +inline tree
>> +strip_array_types (tree type)
>> +{
>> +  while (TREE_CODE (type) == ARRAY_TYPE)
>> +    type = TREE_TYPE (type);
>> +
>> +  return type;
>> +}
>> +
>>   /* Desription of the reason why the argument of valid_constant_size_p
>>      is not a valid size.  */
>>   enum cst_size_error {
>> @@ -5360,8 +5371,6 @@ extern tree create_artificial_label (location_t);
>>   extern const char *get_name (tree);
>>   extern bool stdarg_p (const_tree);
>>   extern bool prototype_p (const_tree);
>> -extern bool is_typedef_decl (const_tree x);
>> -extern bool typedef_variant_p (const_tree);
>>   extern bool auto_var_p (const_tree);
>>   extern bool auto_var_in_fn_p (const_tree, const_tree);
>>   extern tree build_low_bits_mask (tree, unsigned);
>> @@ -5376,6 +5385,23 @@ extern void error_unavailable_use (tree, tree);
>>   extern tree cache_integer_cst (tree, bool might_duplicate = false);
>>   extern const char *combined_fn_name (combined_fn);
>>   
>> +/* Returns true if X is a typedef decl.  */
>> +
>> +inline bool
>> +is_typedef_decl (const_tree x)
>> +{
>> +  return (x && TREE_CODE (x) == TYPE_DECL
>> +	  && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
>> +}
>> +
>> +/* Returns true iff TYPE is a type variant created for a typedef. */
>> +
>> +inline bool
>> +typedef_variant_p (const_tree type)
>> +{
>> +  return is_typedef_decl (TYPE_NAME (type));
>> +}
>> +
>>   /* Compare and hash for any structure which begins with a canonical
>>      pointer.  Assumes all pointers are interchangeable, which is sort
>>      of already assumed by gcc elsewhere IIRC.  */
>> -- 
>> 2.39.0.rc0.49.g083e01275b
>>
>>
>
  

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index addd26ea077..19914d08a03 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -49,7 +49,7 @@  c-common.h, not after.
    but not all node kinds do (e.g. constants, and references to
    params, locals, etc), so we stash a copy here.  */
 
-extern location_t cp_expr_location		(const_tree);
+inline location_t cp_expr_location		(const_tree);
 
 class cp_expr
 {
@@ -8100,7 +8100,6 @@  extern bool error_type_p			(const_tree);
 extern bool ptr_reasonably_similar		(const_tree, const_tree);
 extern tree build_ptrmemfunc			(tree, tree, int, bool,
 						 tsubst_flags_t);
-extern int cp_type_quals			(const_tree);
 extern int type_memfn_quals			(const_tree);
 extern cp_ref_qualifier type_memfn_rqual	(const_tree);
 extern tree apply_memfn_quals			(tree, cp_cv_quals,
@@ -8151,6 +8150,29 @@  extern void maybe_warn_about_useless_cast       (location_t, tree, tree,
 						 tsubst_flags_t);
 extern tree cp_perform_integral_promotions      (tree, tsubst_flags_t);
 
+/* Returns the type qualifiers for this type, including the qualifiers on the
+   elements for an array type.  */
+
+inline int
+cp_type_quals (const_tree type)
+{
+  int quals;
+  /* This CONST_CAST is okay because strip_array_types returns its
+     argument unmodified and we assign it to a const_tree.  */
+  type = strip_array_types (CONST_CAST_TREE (type));
+  if (type == error_mark_node
+      /* Quals on a FUNCTION_TYPE are memfn quals.  */
+      || TREE_CODE (type) == FUNCTION_TYPE)
+    return TYPE_UNQUALIFIED;
+  quals = TYPE_QUALS (type);
+  /* METHOD and REFERENCE_TYPEs should never have quals.  */
+  gcc_checking_assert ((TREE_CODE (type) != METHOD_TYPE
+			&& !TYPE_REF_P (type))
+		       || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
+			   == TYPE_UNQUALIFIED));
+  return quals;
+}
+
 extern tree finish_left_unary_fold_expr      (tree, int);
 extern tree finish_right_unary_fold_expr     (tree, int);
 extern tree finish_binary_fold_expr          (tree, tree, int);
@@ -8168,6 +8190,30 @@  loc_or_input_loc (location_t loc)
   return loc == UNKNOWN_LOCATION ? input_location : loc;
 }
 
+/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
+   locations.  */
+
+inline location_t
+cp_expr_location (const_tree t_)
+{
+  tree t = CONST_CAST_TREE (t_);
+  if (t == NULL_TREE)
+    return UNKNOWN_LOCATION;
+  switch (TREE_CODE (t))
+    {
+    case LAMBDA_EXPR:
+      return LAMBDA_EXPR_LOCATION (t);
+    case STATIC_ASSERT:
+      return STATIC_ASSERT_SOURCE_LOCATION (t);
+    case TRAIT_EXPR:
+      return TRAIT_EXPR_LOCATION (t);
+    case PTRMEM_CST:
+      return PTRMEM_CST_LOCATION (t);
+    default:
+      return EXPR_LOCATION (t);
+    }
+}
+
 inline location_t
 cp_expr_loc_or_loc (const_tree t, location_t or_loc)
 {
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 1487f4975c5..4066b014f6e 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -6214,30 +6214,6 @@  cp_tree_code_length (enum tree_code code)
     }
 }
 
-/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
-   locations.  */
-
-location_t
-cp_expr_location (const_tree t_)
-{
-  tree t = CONST_CAST_TREE (t_);
-  if (t == NULL_TREE)
-    return UNKNOWN_LOCATION;
-  switch (TREE_CODE (t))
-    {
-    case LAMBDA_EXPR:
-      return LAMBDA_EXPR_LOCATION (t);
-    case STATIC_ASSERT:
-      return STATIC_ASSERT_SOURCE_LOCATION (t);
-    case TRAIT_EXPR:
-      return TRAIT_EXPR_LOCATION (t);
-    case PTRMEM_CST:
-      return PTRMEM_CST_LOCATION (t);
-    default:
-      return EXPR_LOCATION (t);
-    }
-}
-
 /* Implement -Wzero_as_null_pointer_constant.  Return true if the
    conditions for the warning hold, false otherwise.  */
 bool
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 7dfe5acc67e..10b7ed020f7 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -11460,29 +11460,6 @@  comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
     }
 }
 
-/* Returns the type qualifiers for this type, including the qualifiers on the
-   elements for an array type.  */
-
-int
-cp_type_quals (const_tree type)
-{
-  int quals;
-  /* This CONST_CAST is okay because strip_array_types returns its
-     argument unmodified and we assign it to a const_tree.  */
-  type = strip_array_types (CONST_CAST_TREE (type));
-  if (type == error_mark_node
-      /* Quals on a FUNCTION_TYPE are memfn quals.  */
-      || TREE_CODE (type) == FUNCTION_TYPE)
-    return TYPE_UNQUALIFIED;
-  quals = TYPE_QUALS (type);
-  /* METHOD and REFERENCE_TYPEs should never have quals.  */
-  gcc_assert ((TREE_CODE (type) != METHOD_TYPE
-	       && !TYPE_REF_P (type))
-	      || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
-		  == TYPE_UNQUALIFIED));
-  return quals;
-}
-
 /* Returns the function-ref-qualifier for TYPE */
 
 cp_ref_qualifier
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 254b2373dcf..5eb6a49da31 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -7253,18 +7253,6 @@  build_array_type_nelts (tree elt_type, poly_uint64 nelts)
   return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
 }
 
-/* Recursively examines the array elements of TYPE, until a non-array
-   element type is found.  */
-
-tree
-strip_array_types (tree type)
-{
-  while (TREE_CODE (type) == ARRAY_TYPE)
-    type = TREE_TYPE (type);
-
-  return type;
-}
-
 /* Computes the canonical argument types from the argument type list
    ARGTYPES.
 
@@ -12132,23 +12120,6 @@  get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
     }
 }
 
-/* Returns true if X is a typedef decl.  */
-
-bool
-is_typedef_decl (const_tree x)
-{
-  return (x && TREE_CODE (x) == TYPE_DECL
-          && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
-}
-
-/* Returns true iff TYPE is a type variant created for a typedef. */
-
-bool
-typedef_variant_p (const_tree type)
-{
-  return is_typedef_decl (TYPE_NAME (type));
-}
-
 /* PR 84195: Replace control characters in "unescaped" with their
    escaped equivalents.  Allow newlines if -fmessage-length has
    been set to a non-zero value.  This is done here, rather than
diff --git a/gcc/tree.h b/gcc/tree.h
index 4a19de1c94d..27001a4dfda 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4807,9 +4807,20 @@  tree_to_poly_uint64 (const_tree t)
 extern int tree_int_cst_sgn (const_tree);
 extern int tree_int_cst_sign_bit (const_tree);
 extern unsigned int tree_int_cst_min_precision (tree, signop);
-extern tree strip_array_types (tree);
 extern tree excess_precision_type (tree);
 
+/* Recursively examines the array elements of TYPE, until a non-array
+   element type is found.  */
+
+inline tree
+strip_array_types (tree type)
+{
+  while (TREE_CODE (type) == ARRAY_TYPE)
+    type = TREE_TYPE (type);
+
+  return type;
+}
+
 /* Desription of the reason why the argument of valid_constant_size_p
    is not a valid size.  */
 enum cst_size_error {
@@ -5360,8 +5371,6 @@  extern tree create_artificial_label (location_t);
 extern const char *get_name (tree);
 extern bool stdarg_p (const_tree);
 extern bool prototype_p (const_tree);
-extern bool is_typedef_decl (const_tree x);
-extern bool typedef_variant_p (const_tree);
 extern bool auto_var_p (const_tree);
 extern bool auto_var_in_fn_p (const_tree, const_tree);
 extern tree build_low_bits_mask (tree, unsigned);
@@ -5376,6 +5385,23 @@  extern void error_unavailable_use (tree, tree);
 extern tree cache_integer_cst (tree, bool might_duplicate = false);
 extern const char *combined_fn_name (combined_fn);
 
+/* Returns true if X is a typedef decl.  */
+
+inline bool
+is_typedef_decl (const_tree x)
+{
+  return (x && TREE_CODE (x) == TYPE_DECL
+	  && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
+}
+
+/* Returns true iff TYPE is a type variant created for a typedef. */
+
+inline bool
+typedef_variant_p (const_tree type)
+{
+  return is_typedef_decl (TYPE_NAME (type));
+}
+
 /* Compare and hash for any structure which begins with a canonical
    pointer.  Assumes all pointers are interchangeable, which is sort
    of already assumed by gcc elsewhere IIRC.  */