]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, tree: declare some basic functions inline
authorPatrick Palka <ppalka@redhat.com>
Mon, 24 Apr 2023 14:33:49 +0000 (10:33 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 24 Apr 2023 14:33:49 +0000 (10:33 -0400)
The functions strip_array_types, is_typedef_decl, typedef_variant_p
and cp_expr_location are used throughout the C++ front end 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.

So this patch moves their definitions into the appropriate headers to
enable inlining them.

gcc/cp/ChangeLog:

* cp-tree.h (cp_expr_location): Define here.
* tree.cc (cp_expr_location): 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
gcc/cp/tree.cc
gcc/tree.cc
gcc/tree.h

index 6c5920dcbe07dd923407ea38c69f92aa48af6f8f..c9c4cd6f32fd58fd2f7c66c23ddf2509804e110e 100644 (file)
@@ -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
 {
@@ -8163,6 +8163,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)
 {
index d35e30faf2870aa143c83b751a39d25212f948f4..131b212ff73e2e5d4a2a154d33c55f4237dfcb8a 100644 (file)
@@ -6221,30 +6221,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
index 5f2af073af9a823a8d834920daff1f070e640de5..8394ff0f8378581d4803c5abec8e20246a397ad4 100644 (file)
@@ -7312,18 +7312,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.
 
@@ -12213,23 +12201,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
index 8e67e7078d1cb4b33b523cf7849321ef807ece22..dc94c17db76269faf44e14b3206feb4b23156014 100644 (file)
@@ -4821,9 +4821,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 {
@@ -5374,8 +5385,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);
@@ -5391,6 +5400,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.  */