public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1102] gen: Allow unspec numbers in .md attributes
Date: Wed, 15 Jun 2022 10:13:02 +0000 (GMT)	[thread overview]
Message-ID: <20220615101302.20A2C3856265@sourceware.org> (raw)

https://gcc.gnu.org/g:183a4f3829243b43a28fc70e59129521033b8f8a

commit r13-1102-g183a4f3829243b43a28fc70e59129521033b8f8a
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Jun 15 11:12:51 2022 +0100

    gen: Allow unspec numbers in .md attributes
    
    Tamar pointed out that:
    
      (unspec:M ... <FOO>)
    
    didn't work when a value of attribute FOO was defined by
    define_constant, such as in:
    
      (define_int_attribute FOO [(UNSPEC_A "UNSPEC_B") ...])
    
    This is because symbolic constants are substituted during lexing
    and only apply to bare symbol names, not strings.
    
    One option would have been to extend this lexing substitution
    to define_*_attribute values as well.  However, that would replace
    symbolic names with integer constants in the generated .cc code,
    making it less readable.
    
    This patch goes for the more localised approach of only
    applying define_constants when we want their integer value.
    
    I don't think any changes to the docs are needed.  This isn't
    adding a new feature, it's just making an existing one work in
    the expected way.
    
    gcc/
            * read-rtl.cc (find_int): Substitute symbolic constants
            before converting the string to an integer.

Diff:
---
 gcc/read-rtl.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc
index 798d2485991..62c7895af60 100644
--- a/gcc/read-rtl.cc
+++ b/gcc/read-rtl.cc
@@ -284,6 +284,12 @@ find_int (const char *name)
 {
   HOST_WIDE_INT tmp;
 
+  struct md_constant tmp_def;
+  tmp_def.name = const_cast<char *> (name);
+  auto htab = rtx_reader_ptr->get_md_constants ();
+  if (auto def = (struct md_constant *) htab_find (htab, &tmp_def))
+    name = def->value;
+
   validate_const_int (name);
 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
   tmp = atoi (name);


                 reply	other threads:[~2022-06-15 10:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220615101302.20A2C3856265@sourceware.org \
    --to=rsandifo@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).