aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc/extend.texi
diff options
context:
space:
mode:
authorJavier Martinez <javier.martinez.bugzilla@gmail.com>2023-08-23 15:02:40 +0200
committerJason Merrill <jason@redhat.com>2023-09-19 15:03:28 -0400
commit4f52e61e0665e760b95975b4d49437873967be2e (patch)
treed295e1e617ed5c9275f70a637703c30511c06aa9 /gcc/doc/extend.texi
parentb9912332c5b6fc9433ee11f5488acad117868888 (diff)
downloadgcc-4f52e61e0665e760b95975b4d49437873967be2e.zip
gcc-4f52e61e0665e760b95975b4d49437873967be2e.tar.gz
gcc-4f52e61e0665e760b95975b4d49437873967be2e.tar.bz2
c++: extend cold, hot attributes to classes
Most code is cold. This patch extends support for attribute ((cold)) to C++ Classes, Unions, and Structs (RECORD_TYPES and UNION_TYPES) to benefit from encapsulation - reducing the verbosity of using the attribute where deserved. The ((hot)) attribute is also extended for its semantic relation. gcc/c-family/ChangeLog: * c-attribs.cc (handle_hot_attribute): remove warning on RECORD_TYPE and UNION_TYPE when in c_dialect_xx. (handle_cold_attribute): Likewise. gcc/cp/ChangeLog: * class.cc (propagate_class_warmth_attribute): New function. (check_bases_and_members): propagate hot and cold attributes to all FUNCTION_DECL when the record is marked hot or cold. * cp-tree.h (maybe_propagate_warmth_attributes): New function. * decl2.cc (maybe_propagate_warmth_attributes): New function. * method.cc (lazily_declare_fn): propagate hot and cold attributes to lazily declared functions when the record is marked hot or cold. gcc/ChangeLog: * doc/extend.texi: Document attributes hot, cold on C++ types. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-hotness.C: New test. Signed-off-by: Javier Martinez <javier.martinez.bugzilla@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/doc/extend.texi')
-rw-r--r--gcc/doc/extend.texi37
1 files changed, 35 insertions, 2 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 947c05b..be04604 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2874,7 +2874,10 @@ improving code locality of non-cold parts of program. The paths leading
to calls of cold functions within code are marked as unlikely by the branch
prediction mechanism. It is thus useful to mark functions used to handle
unlikely conditions, such as @code{perror}, as cold to improve optimization
-of hot functions that do call marked functions in rare occasions.
+of hot functions that do call marked functions in rare occasions. In C++,
+the @code{cold} attribute can be applied to types with the effect of being
+propagated to member functions. See
+@ref{C++ Attributes}.
When profile feedback is available, via @option{-fprofile-use}, cold functions
are automatically detected and this attribute is ignored.
@@ -3293,7 +3296,9 @@ The @code{hot} attribute on a function is used to inform the compiler that
the function is a hot spot of the compiled program. The function is
optimized more aggressively and on many targets it is placed into a special
subsection of the text section so all hot functions appear close together,
-improving locality.
+improving locality. In C++, the @code{hot} attribute can be applied to types
+with the effect of being propagated to member functions. See
+@ref{C++ Attributes}.
When profile feedback is available, via @option{-fprofile-use}, hot functions
are automatically detected and this attribute is ignored.
@@ -25605,6 +25610,34 @@ control a resource, such as @code{std::lock_guard}.
This attribute is also accepted in C, but it is unnecessary because C
does not have constructors or destructors.
+@cindex @code{cold} type attribute
+@item cold
+
+In addition to functions and labels, GNU C++ allows the @code{cold}
+attribute to be used on C++ classes, structs, or unions. Applying
+the @code{cold} attribute on a type has the effect of treating every
+member function of the type, including implicit special member
+functions, as cold. If a member function is marked with the
+@code{hot} function attribute, the @code{hot} attribute takes
+precedence and the @code{cold} attribute is not propagated.
+
+For the effects of the @code{cold} attribute on functions, see
+@ref{Common Function Attributes}.
+
+@cindex @code{hot} type attribute
+@item hot
+
+In addition to functions and labels, GNU C++ allows the @code{hot}
+attribute to be used on C++ classes, structs, or unions. Applying
+the @code{hot} attribute on a type has the effect of treating every
+member function of the type, including implicit special member
+functions, as hot. If a member function is marked with the
+@code{cold} function attribute, the @code{cold} attribute takes
+precedence and the @code{hot} attribute is not propagated.
+
+For the effects of the @code{hot} attribute on functions, see
+@ref{Common Function Attributes}.
+
@end table
@node Function Multiversioning