mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
c++: Save 8 further bytes from lang_type allocations
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.
This commit is contained in:
committed by
Jakub Jelinek
parent
8f063b40e5
commit
bdb0a6be69
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user