]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Save 8 further bytes from lang_type allocations
authorJakub Jelinek <jakub@redhat.com>
Thu, 10 Jul 2025 22:05:23 +0000 (00:05 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 10 Jul 2025 22:05:23 +0000 (00:05 +0200)
The following patch implements the
/* FIXME reuse another field?  */
comment on the lambda_expr member.
I think (and asserts in the patch seem to confirm) CLASSTYPE_KEY_METHOD
is only ever non-NULL for TYE_POLYMORPHIC_P and on the other side
CLASSTYPE_LAMBDA_EXPR is only used on closure types which are never
polymorphic.

So, the patch just uses one member for both, with the accessor macros
changed to be no longer lvalues and adding SET_* variants of the macros
for setters.

2025-07-11  Jakub Jelinek  <jakub@redhat.com>

* cp-tree.h (struct lang_type): Add comment before key_method.
Remove lambda_expr.
(CLASSTYPE_KEY_METHOD): Give NULL_TREE if not TYPE_POLYMORPHIC_P.
(SET_CLASSTYPE_KEY_METHOD): Define.
(CLASSTYPE_LAMBDA_EXPR): Give NULL_TREE if TYPE_POLYMORPHIC_P.
Use key_method member instead of lambda_expr.
(SET_CLASSTYPE_LAMBDA_EXPR): Define.
* class.cc (determine_key_method): Use SET_CLASSTYPE_KEY_METHOD
macro.
* decl.cc (xref_tag): Use SET_CLASSTYPE_LAMBDA_EXPR macro.
* lambda.cc (begin_lambda_type): Likewise.
* module.cc (trees_in::read_class_def): Use SET_CLASSTYPE_LAMBDA_EXPR
and SET_CLASSTYPE_KEY_METHOD macros, assert lambda is NULL if
TYPE_POLYMORPHIC_P and otherwise assert key_method is NULL.

gcc/cp/class.cc
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/lambda.cc
gcc/cp/module.cc

index 9a41c00788a83743a11ac149145ddd889b3d289a..151ee2bc4714b3996150c28f29a941819e7eb5a4 100644 (file)
@@ -7452,7 +7452,7 @@ determine_key_method (tree type)
        && ! DECL_DECLARED_INLINE_P (method)
        && ! DECL_PURE_VIRTUAL_P (method))
       {
-       CLASSTYPE_KEY_METHOD (type) = method;
+       SET_CLASSTYPE_KEY_METHOD (type, method);
        break;
       }
 
index 43705733d5147ccec9cc0d79fb10faa793ee3972..90816281224d2e3471d6e4553e003fb9ee258252 100644 (file)
@@ -2519,11 +2519,11 @@ struct GTY(()) lang_type {
   vec<tree, va_gc> *pure_virtuals;
   tree friend_classes;
   vec<tree, va_gc> * GTY((reorder ("resort_type_member_vec"))) members;
+  /* CLASSTYPE_KEY_METHOD for TYPE_POLYMORPHIC_P types, CLASSTYPE_LAMBDA_EXPR
+     otherwise.  */
   tree key_method;
   tree decl_list;
   tree befriending_classes;
-  /* FIXME reuse another field?  */
-  tree lambda_expr;
   union maybe_objc_info {
     /* If not c_dialect_objc, this part is not even allocated.  */
     char GTY((tag ("0"))) non_objc;
@@ -2646,7 +2646,13 @@ struct GTY(()) lang_type {
 /* The member function with which the vtable will be emitted:
    the first noninline non-pure-virtual member function.  NULL_TREE
    if there is no key function or if this is a class template */
-#define CLASSTYPE_KEY_METHOD(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->key_method)
+#define CLASSTYPE_KEY_METHOD(NODE) \
+  (TYPE_POLYMORPHIC_P (NODE)                                   \
+   ? LANG_TYPE_CLASS_CHECK (NODE)->key_method                  \
+   : NULL_TREE)
+#define SET_CLASSTYPE_KEY_METHOD(NODE, VALUE) \
+  (gcc_checking_assert (TYPE_POLYMORPHIC_P (NODE)),            \
+   LANG_TYPE_CLASS_CHECK (NODE)->key_method = (VALUE))
 
 /* Vector of members.  During definition, it is unordered and only
    member functions are present.  After completion it is sorted and
@@ -2778,7 +2784,12 @@ struct GTY(()) lang_type {
 
 /* The associated LAMBDA_EXPR that made this class.  */
 #define CLASSTYPE_LAMBDA_EXPR(NODE) \
-  (LANG_TYPE_CLASS_CHECK (NODE)->lambda_expr)
+  (TYPE_POLYMORPHIC_P (NODE)                           \
+   ? NULL_TREE                                         \
+   : LANG_TYPE_CLASS_CHECK (NODE)->key_method)
+#define SET_CLASSTYPE_LAMBDA_EXPR(NODE, VALUE) \
+  (gcc_checking_assert (!TYPE_POLYMORPHIC_P (NODE)),   \
+   LANG_TYPE_CLASS_CHECK (NODE)->key_method = (VALUE))
 /* The extra mangling scope for this closure type.  */
 #define LAMBDA_TYPE_EXTRA_SCOPE(NODE) \
   (LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR (NODE)))
index 664dbbec279650996f022b320042095ead3a1e32..843f0e4fd160e3a480cc5e37e9c38817fe03d6f1 100644 (file)
@@ -17289,7 +17289,7 @@ xref_tag (enum tag_types tag_code, tree name,
       if (IDENTIFIER_LAMBDA_P (name))
        /* Mark it as a lambda type right now.  Our caller will
           correct the value.  */
-       CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node;
+       SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
       t = pushtag (name, t, how);
     }
   else
index 182cffaf8d4f5158748104f41a73b699c6b334fe..525e8ef4b341e31f04bb6dd51a94d0098914cfeb 100644 (file)
@@ -150,7 +150,7 @@ begin_lambda_type (tree lambda)
 
   /* Cross-reference the expression and the type.  */
   LAMBDA_EXPR_CLOSURE (lambda) = type;
-  CLASSTYPE_LAMBDA_EXPR (type) = lambda;
+  SET_CLASSTYPE_LAMBDA_EXPR (type, lambda);
 
   /* In C++17, assume the closure is literal; we'll clear the flag later if
      necessary.  */
index 6b5a60a3f3ec7e84b68bc4335230bd4270a425ee..689319ad9213710d0137395d9ea69435e0ce999f 100644 (file)
@@ -13393,13 +13393,19 @@ trees_in::read_class_def (tree defn, tree maybe_template)
 
       if (TYPE_LANG_SPECIFIC (type))
        {
-         CLASSTYPE_LAMBDA_EXPR (type) = lambda;
+         if (!TYPE_POLYMORPHIC_P (type))
+           SET_CLASSTYPE_LAMBDA_EXPR (type, lambda);
+         else
+           gcc_checking_assert (lambda == NULL_TREE);
 
          CLASSTYPE_MEMBER_VEC (type) = member_vec;
          CLASSTYPE_PURE_VIRTUALS (type) = pure_virts;
          CLASSTYPE_VCALL_INDICES (type) = vcall_indices;
 
-         CLASSTYPE_KEY_METHOD (type) = key_method;
+         if (TYPE_POLYMORPHIC_P (type))
+           SET_CLASSTYPE_KEY_METHOD (type, key_method);
+         else
+           gcc_checking_assert (key_method == NULL_TREE);
 
          CLASSTYPE_VBASECLASSES (type) = vbase_vec;