public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] gen: Allow unspec numbers in .md attributes
@ 2022-06-15 10:14 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2022-06-15 10:14 UTC (permalink / raw)
  To: gcc-patches

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.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  Also tested
by making sure that Tamar's test patch now compiles.

Richard


gcc/
	* read-rtl.cc (find_int): Substitute symbolic constants
	before converting the string to an integer.
---
 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);
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-15 10:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 10:14 [pushed] gen: Allow unspec numbers in .md attributes Richard Sandiford

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).