From patchwork Tue May 23 10:36:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1785081 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=uOTCDurn; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QQWDV5fwYz20Pr for ; Tue, 23 May 2023 20:45:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32E523858410 for ; Tue, 23 May 2023 10:45:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32E523858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684838709; bh=bXzMdxv7iTGow/PN6cOPwouC7jBE/Ro38d93wQZtRjo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uOTCDurnRlmPmfa4SwzdhzemHf2B++u7E7v6F7c/G+tslYXYYc20Pz3s7wM3ss9oQ QIdGapONpYPpMCxKPEilRXF1w41l/TD9+MDa7NQn/IxUfYJQm2bgv8ghWvFUyTopTa 9ksqui7xhWRj+DTQSgD1X9+x1S1L9F632Ekgqb3k= 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 7212E3858D37 for ; Tue, 23 May 2023 10:44:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7212E3858D37 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 2CFAD139F for ; Tue, 23 May 2023 03:45:34 -0700 (PDT) Received: from localhost (unknown [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C12A73F6C4 for ; Tue, 23 May 2023 03:36:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 1/2] md: Allow to refer to the value of int iterator FOO Date: Tue, 23 May 2023 11:36:16 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-26.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, MEDICAL_SUBJECT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In a follow-up patch, I wanted to use an int iterator to iterate over various possible values of a const_int. But one problem with int iterators was that there was no way of referring to the current value of the iterator. This is unlike modes and codes, which provide automatic "mode", "MODE", "code" and "CODE" attribbutes. These automatic definitions are the equivalent of an explicit: (define_mode_attr mode [(QI "qi") (HI "hi") ...]) We obviously can't do that for every possible value of an int. One option would have been to go for some kind of lazily-populated attribute. But that sounds quite complicated. This patch instead goes for the simpler approach of allowing to refer to the current value of FOO. In principle it would be possible to allow the same thing for mode and code iterators. But for modes there are at least 4 realistic possiblities: - the E_* enumeration value (which is what this patch would give) - the user-facing C token, like DImode, SFmode, etc. - the equivalent of - the equivalent of Because of this ambiguity, it seemed better to stick to the current approach for modes. For codes it's less clear-cut, but and are both realistic possibilities, so again it seemed better to be explicit. The patch also removes “Each @var{int} must have the same rtx format. @xref{RTL Classes}.”, which was erroneously copied from the code iterator section. Tested on aarch64-linux-gnu and x86_64-linux-gnu. Also tested by checking that no port had an int iterator whose name matched an existing attribute. Pushed to trunk. Richard gcc/ * doc/md.texi: Document that can be used to refer to the numerical value of an int iterator FOO. Tweak other parts of the int iterator documentation. * read-rtl.cc (iterator_group::has_self_attr): New field. (map_attr_string): When has_self_attr is true, make expand to the current value of iterator FOO. (initialize_iterators): Set has_self_attr for int iterators. --- gcc/doc/md.texi | 15 +++++++++------ gcc/read-rtl.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 8ebce31ba78..6a435eb4461 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -11502,11 +11502,10 @@ The construct: @end smallexample defines a pseudo integer constant @var{name} that can be instantiated as -@var{inti} if condition @var{condi} is true. Each @var{int} must have the -same rtx format. @xref{RTL Classes}. Int iterators can appear in only -those rtx fields that have 'i', 'n', 'w', or 'p' as the specifier. This -means that each @var{int} has to be a constant defined using define_constant -or define_c_enum. +@var{inti} if condition @var{condi} is true. Int iterators can appear in +only those rtx fields that have `i', `n', `w', or `p' as the specifier. +This means that each @var{int} has to be a constant defined using +@samp{define_constant} or @samp{define_c_enum}. As with mode and code iterators, each pattern that uses @var{name} will be expanded @var{n} times, once with all uses of @var{name} replaced by @@ -11517,9 +11516,13 @@ It is possible to define attributes for ints as well as for codes and modes. Attributes are defined using: @smallexample -(define_int_attr @var{name} [(@var{int1} "@var{value1}") @dots{} (@var{intn} "@var{valuen}")]) +(define_int_attr @var{attr_name} [(@var{int1} "@var{value1}") @dots{} (@var{intn} "@var{valuen}")]) @end smallexample +In additon to these user-defined attributes, it is possible to use +@samp{<@var{name}>} to refer to the current expansion of iterator +@var{name} (such as @var{int1}, @var{int2}, and so on). + Here's an example of int iterators in action, taken from the ARM port: @smallexample diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc index 8cb25aebdbb..292f8b72d43 100644 --- a/gcc/read-rtl.cc +++ b/gcc/read-rtl.cc @@ -80,6 +80,12 @@ struct iterator_group { /* Return the C token for the given standard mode, code, etc. */ const char *(*get_c_token) (int); + + /* True if each iterator name should be treated as an attribute that + maps to the C token produced by get_c_token. This means that for + an iterator ITER, can be used in strings to refer to the + current value of ITER, as a C token. */ + bool has_self_attr; }; /* Records one use of an iterator. */ @@ -472,6 +478,25 @@ map_attr_string (file_location loc, const char *p, mapping **iterator_out = 0) || iterator->name[iterator_name_len] != 0)) continue; + if (iterator->group->has_self_attr + && strcmp (attr, iterator->name) == 0) + { + if (iterator_out) + *iterator_out = iterator; + int number = iterator->current_value->number; + const char *string = iterator->group->get_c_token (number); + if (res && strcmp (string, res->string) != 0) + { + error_at (loc, "ambiguous attribute '%s'; could be" + " '%s' (via '%s:%s') or '%s' (via '%s:%s')", + attr, res->string, prev->name, attr, + string, iterator->name, attr); + return res; + } + prev = iterator; + res = new map_value { nullptr, number, string }; + } + /* Find the attribute specification. */ m = (struct mapping *) htab_find (iterator->group->attrs, &attr); if (m) @@ -1035,6 +1060,7 @@ initialize_iterators (void) ints.find_builtin = find_int; ints.apply_iterator = apply_int_iterator; ints.get_c_token = get_int_token; + ints.has_self_attr = true; substs.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); substs.iterators = htab_create (13, leading_string_hash,