On 8/8/24 11:31 AM, Patrick Palka wrote:
The predicates for checking an IDENTIFIER node's cp_identifier_kind
currently directly test the three flag bits that encode the kind. This
patch instead makes the checks first reconstruct the cp_identifier_kind
in its entirety and then compare that.
OK.
gcc/cp/ChangeLog:
* cp-tree.h (get_identifier_kind): Define.
(IDENTIFIER_KEYWORD_P): Redefine using get_identifier_kind.
(IDENTIFIER_CDTOR_P): Likewise.
(IDENTIFIER_CTOR_P): Likewise.
(IDENTIFIER_DTOR_P): Likewise.
(IDENTIFIER_ANY_OP_P): Likewise.
(IDENTIFIER_OVL_OP_P): Likewise.
(IDENTIFIER_ASSIGN_OP_P): Likewise.
(IDENTIFIER_CONV_OP_P): Likewise.
(IDENTIFIER_TRAIT_P): Likewise.
* parser.cc (cp_lexer_peek_trait): Mark IDENTIFIER_TRAIT_P
test UNLIKELY.
---
gcc/cp/cp-tree.h | 41 +++++++++++++++++++++--------------------
gcc/cp/parser.cc | 3 ++-
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b81bc91208f..0c25ec5a04e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1255,56 +1255,57 @@ enum cp_identifier_kind {
#define IDENTIFIER_VIRTUAL_P(NODE) \
TREE_LANG_FLAG_5 (IDENTIFIER_NODE_CHECK (NODE))
+/* Return the cp_identifier_kind of the given IDENTIFIER node ID. */
+
+ATTRIBUTE_PURE inline cp_identifier_kind
+get_identifier_kind (tree id)
+{
+ unsigned bit0 = IDENTIFIER_KIND_BIT_0 (id);
+ unsigned bit1 = IDENTIFIER_KIND_BIT_1 (id);
+ unsigned bit2 = IDENTIFIER_KIND_BIT_2 (id);
+ return cp_identifier_kind ((bit2 << 2) | (bit1 << 1) | bit0);
+}
+
/* True if this identifier is a reserved word. C_RID_CODE (node) is
then the RID_* value of the keyword. Value 1. */
#define IDENTIFIER_KEYWORD_P(NODE) \
- ((!IDENTIFIER_KIND_BIT_2 (NODE)) \
- & (!IDENTIFIER_KIND_BIT_1 (NODE)) \
- & IDENTIFIER_KIND_BIT_0 (NODE))
+ (get_identifier_kind (NODE) == cik_keyword)
/* True if this identifier is the name of a constructor or
destructor. Value 2 or 3. */
#define IDENTIFIER_CDTOR_P(NODE) \
- ((!IDENTIFIER_KIND_BIT_2 (NODE)) \
- & IDENTIFIER_KIND_BIT_1 (NODE))
+ (IDENTIFIER_CTOR_P (NODE) || IDENTIFIER_DTOR_P (NODE))
/* True if this identifier is the name of a constructor. Value 2. */
#define IDENTIFIER_CTOR_P(NODE) \
- (IDENTIFIER_CDTOR_P(NODE) \
- & (!IDENTIFIER_KIND_BIT_0 (NODE)))
+ (get_identifier_kind (NODE) == cik_ctor)
/* True if this identifier is the name of a destructor. Value 3. */
#define IDENTIFIER_DTOR_P(NODE) \
- (IDENTIFIER_CDTOR_P(NODE) \
- & IDENTIFIER_KIND_BIT_0 (NODE))
+ (get_identifier_kind (NODE) == cik_dtor)
/* True if this identifier is for any operator name (including
conversions). Value 4, 5, or 6. */
#define IDENTIFIER_ANY_OP_P(NODE) \
- (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE))
+ (IDENTIFIER_OVL_OP_P (NODE) || IDENTIFIER_CONV_OP_P (NODE))
/* True if this identifier is for an overloaded operator. Values 4, 5. */
#define IDENTIFIER_OVL_OP_P(NODE) \
- (IDENTIFIER_ANY_OP_P (NODE) \
- & (!IDENTIFIER_KIND_BIT_1 (NODE)))
+ (get_identifier_kind (NODE) == cik_simple_op \
+ || get_identifier_kind (NODE) == cik_assign_op)
/* True if this identifier is for any assignment. Values 5. */
#define IDENTIFIER_ASSIGN_OP_P(NODE) \
- (IDENTIFIER_OVL_OP_P (NODE) \
- & IDENTIFIER_KIND_BIT_0 (NODE))
+ (get_identifier_kind (NODE) == cik_assign_op)
/* True if this identifier is the name of a type-conversion
operator. Value 6. */
#define IDENTIFIER_CONV_OP_P(NODE) \
- (IDENTIFIER_ANY_OP_P (NODE) \
- & IDENTIFIER_KIND_BIT_1 (NODE) \
- & (!IDENTIFIER_KIND_BIT_0 (NODE)))
+ (get_identifier_kind (NODE) == cik_conv_op)
/* True if this identifier is the name of a built-in trait. */
#define IDENTIFIER_TRAIT_P(NODE) \
- (IDENTIFIER_KIND_BIT_0 (NODE) \
- & IDENTIFIER_KIND_BIT_1 (NODE) \
- & IDENTIFIER_KIND_BIT_2 (NODE))
+ (get_identifier_kind (NODE) == cik_trait)
/* True if this identifier is a new or delete operator. */
#define IDENTIFIER_NEWDEL_OP_P(NODE) \
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index f625b0a310c..60ff41ec9fa 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1198,7 +1198,8 @@ static const cp_trait *
cp_lexer_peek_trait (cp_lexer *lexer)
{
const cp_token *token1 = cp_lexer_peek_token (lexer);
- if (token1->type == CPP_NAME && IDENTIFIER_TRAIT_P (token1->u.value))
+ if (token1->type == CPP_NAME
+ && UNLIKELY (IDENTIFIER_TRAIT_P (token1->u.value)))
{
const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX
(token1->u.value)];
const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT);