From patchwork Wed Jul 17 18:37:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1961753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPPnN6fbbz1xqc for ; Thu, 18 Jul 2024 04:37:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A19ED3860769 for ; Wed, 17 Jul 2024 18:37:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id B08EF3858C48 for ; Wed, 17 Jul 2024 18:37:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B08EF3858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B08EF3858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721241441; cv=none; b=pjRpISJlLIgo9bOm1mVfsKKgt3TuIZqZg1JRy3EBnT3L5W9PTMSJa2LZ18lodSsG9iz7yAtBgi+9Mar7SK00Tv5Tp9KAxnRaFghNATI1nowogriw+CcMfn3NB/cjJM7iNksN7Y86zs0UHCNBpnO6N28lYcWyhLBxQCcoQGN8Jc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721241441; c=relaxed/simple; bh=S9SDw4Y/NrtkYknwC6zT/u2WAGzpViIkSOraO4eo/k8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IGyKFb2Pm0zwy9Y4aYfHmn1UbArH7hPqSWTo9jth+HlkjAe045s6Ejwq+Xm4FeZoqFcaj5RiVyRBDtzle+5wn+6WihCZI1l4feMduYYghu8aSlcR4/KgXvLLOrRc237IcFkKO8C+Z0KoGXFZbnt2NHyFTvEyu0Kcz817myyibxQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0C5D1063 for ; Wed, 17 Jul 2024 11:37:44 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1F0253F73F for ; Wed, 17 Jul 2024 11:37:19 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [pushed] genattrtab: Drop enum tags, consolidate type names Date: Wed, 17 Jul 2024 19:37:17 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Status: No, score=-19.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org genattrtab printed an "enum" tag before references to attribute enums, but that's redundant in C++. Removing it means that each attribute type becomes a single token and can be easily stored in the attr_desc structure. Tested on aarch64-linux-gnu and using contrib/config-list.mk (to make sure that removing "enum" didn't introduce a name clash). Pushed to trunk. Richard gcc/ * genattrtab.cc (attr_desc::cxx_type): New field. (write_attr_get, write_attr_value): Use it. (gen_attr, find_attr, make_internal_attr): Initialize it, dropping enum tags. --- gcc/genattrtab.cc | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/gcc/genattrtab.cc b/gcc/genattrtab.cc index 03c7d6c74a3..2a51549ddd4 100644 --- a/gcc/genattrtab.cc +++ b/gcc/genattrtab.cc @@ -175,6 +175,7 @@ class attr_desc public: char *name; /* Name of attribute. */ const char *enum_name; /* Enum name for DEFINE_ENUM_NAME. */ + const char *cxx_type; /* The associated C++ type. */ class attr_desc *next; /* Next attribute. */ struct attr_value *first_value; /* First value of this attribute. */ struct attr_value *default_val; /* Default value for this attribute. */ @@ -3083,6 +3084,7 @@ gen_attr (md_rtx_info *info) if (GET_CODE (def) == DEFINE_ENUM_ATTR) { attr->enum_name = XSTR (def, 1); + attr->cxx_type = attr->enum_name; et = rtx_reader_ptr->lookup_enum_type (XSTR (def, 1)); if (!et || !et->md_p) error_at (info->loc, "No define_enum called `%s' defined", @@ -3092,9 +3094,13 @@ gen_attr (md_rtx_info *info) add_attr_value (attr, ev->name); } else if (*XSTR (def, 1) == '\0') - attr->is_numeric = 1; + { + attr->is_numeric = 1; + attr->cxx_type = "int"; + } else { + attr->cxx_type = concat ("attr_", attr->name, nullptr); name_ptr = XSTR (def, 1); while ((p = next_comma_elt (&name_ptr)) != NULL) add_attr_value (attr, p); @@ -4052,12 +4058,7 @@ write_attr_get (FILE *outf, class attr_desc *attr) /* Write out start of function, then all values with explicit `case' lines, then a `default', then the value with the most uses. */ - if (attr->enum_name) - fprintf (outf, "enum %s\n", attr->enum_name); - else if (!attr->is_numeric) - fprintf (outf, "enum attr_%s\n", attr->name); - else - fprintf (outf, "int\n"); + fprintf (outf, "%s\n", attr->cxx_type); /* If the attribute name starts with a star, the remainder is the name of the subroutine to use, instead of `get_attr_...'. */ @@ -4103,13 +4104,8 @@ write_attr_get (FILE *outf, class attr_desc *attr) cached_attrs[j] = name; cached_attr = find_attr (&name, 0); gcc_assert (cached_attr && cached_attr->is_const == 0); - if (cached_attr->enum_name) - fprintf (outf, " enum %s", cached_attr->enum_name); - else if (!cached_attr->is_numeric) - fprintf (outf, " enum attr_%s", cached_attr->name); - else - fprintf (outf, " int"); - fprintf (outf, " cached_%s ATTRIBUTE_UNUSED;\n", name); + fprintf (outf, " %s cached_%s ATTRIBUTE_UNUSED;\n", + cached_attr->cxx_type, name); j++; } cached_attr_count = j; @@ -4395,14 +4391,7 @@ write_attr_value (FILE *outf, class attr_desc *attr, rtx value) case ATTR: { class attr_desc *attr2 = find_attr (&XSTR (value, 0), 0); - if (attr->enum_name) - fprintf (outf, "(enum %s)", attr->enum_name); - else if (!attr->is_numeric) - fprintf (outf, "(enum attr_%s)", attr->name); - else if (!attr2->is_numeric) - fprintf (outf, "(int)"); - - fprintf (outf, "get_attr_%s (%s)", attr2->name, + fprintf (outf, "(%s) get_attr_%s (%s)", attr->cxx_type, attr2->name, (attr2->is_const ? "" : "insn")); } break; @@ -4672,7 +4661,8 @@ find_attr (const char **name_p, int create) attr = oballoc (class attr_desc); attr->name = DEF_ATTR_STRING (name); - attr->enum_name = 0; + attr->enum_name = nullptr; + attr->cxx_type = nullptr; attr->first_value = attr->default_val = NULL; attr->is_numeric = attr->is_const = attr->is_special = 0; attr->next = attrs[index]; @@ -4693,6 +4683,7 @@ make_internal_attr (const char *name, rtx value, int special) attr = find_attr (&name, 1); gcc_assert (!attr->default_val); + attr->cxx_type = "int"; attr->is_numeric = 1; attr->is_const = 0; attr->is_special = (special & ATTR_SPECIAL) != 0;