public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Richard Earnshaw (lists)" <Richard.Earnshaw@arm.com>
To: Tamar Christina <Tamar.Christina@arm.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	nd <nd@arm.com>,
	richard.sandiford@arm.com
Subject: Re: [PATCH v2] machine descriptor: New compact syntax for insn and insn_split in Machine Descriptions.
Date: Tue, 6 Jun 2023 17:13:24 +0100	[thread overview]
Message-ID: <dec5d001-d0cc-7d3d-00b3-00ef417d1e7b@arm.com> (raw)
In-Reply-To: <mpt4jnksqkz.fsf@arm.com>

On 06/06/2023 13:49, Richard Sandiford via Gcc-patches wrote:
> Tamar Christina <Tamar.Christina@arm.com> writes:
>>>>     int operand_number;		/* Operand index in the big array.  */
>>>>     int output_format;		/* INSN_OUTPUT_FORMAT_*.  */
>>>> +  bool compact_syntax_p;
>>>>     struct operand_data operand[MAX_MAX_OPERANDS];  };
>>>>
>>>> @@ -700,12 +702,57 @@ process_template (class data *d, const char
>>> *template_code)
>>>>   	  if (sp != ep)
>>>>   	    message_at (d->loc, "trailing whitespace in output template");
>>>>
>>>> -	  while (cp < sp)
>>>> +	  /* Check for any unexpanded iterators.  */
>>>> +	  if (bp[0] != '*' && d->compact_syntax_p)
>>>
>>> I assume the bp[0] != '*' condition skips the check for C code blocks.
>>> Genuine question, but are you sure we want that?  C code often includes asm
>>> strings (in quotes), such as for the SVE CNT[BHWD] example.
>>>
>>> Extending the check would mean that any use of <...> for C++ templates will
>>> need to be quoted, but explicit instantiation is pretty rare in .md files.  It would
>>> also look weird for conditions.
>>>
>>> Either way is fine, just asking.
>>
>> I excluded it entirely to avoid also running afoul of the binary operators. So e.g.
>> * a < b && b > c ? foo : bar shouldn't trigger it.   It seemed more trouble than it's
>> worth to try to get correct.
> 
> Yeah.  I agree it's probably better to skip.
> 
>>>> +  }
>>>> +
>>>> +  /* Adds a character to the end of the string.  */  void add (char
>>>> + c)  {
>>>> +    con += c;
>>>> +  }
>>>> +
>>>> +  /* Output the string in the form of a brand-new char *, then effectively
>>>> +     clear the internal string by resetting len to 0.  */  char * out
>>>> + ()
>>>
>>> Formatting: no need for a space before "out".
>>>
>>>> +  {
>>>> +    /* Final character is always a trailing comma, so strip it out.
>>>> + */
>>>
>>> trailing ',', ';' or ']', rather than just a comma?
>>
>> Ah no, this is a bit of a lazy intercalate, when the alternatives are pushed in it's
>> not easy to tell how many there will be (because we don't keep track of it in this part),
>> so we just always add a trailing "," and ignore the last char on output.  Validation of the
>> alternative counts themselves is done later by the normal machinery.
> 
> Ah, I get it now, thanks.
> 
>>>> +    }
>>>> +
>>>> +  return index;
>>>> +}
>>>> +
>>>> +/* Modify the attributes list to make space for the implicitly declared
>>>> +   attributes in the attrs: list.  */
>>>> +
>>>> +static void
>>>> +create_missing_attributes (rtx x, file_location /* loc */,
>>>> +vec_conlist &attrs) {
>>>> +  if (attrs.empty ())
>>>> +    return;
>>>> +
>>>> +  unsigned int attr_index = GET_CODE (x) == DEFINE_INSN ? 4 : 3;
>>>> + vec_conlist missing;
>>>> +
>>>> +  /* This is an O(n*m) loop but it's fine, both n and m will always be very
>>>> +     small.  */
>>>
>>> Agreed that quadraticness isn't a problem.  But I wonder how many people
>>> would write an explicit placeholder set_attr.  Unlike match_operand and
>>> match_scratch, a placeholder set_attr doesn't carry any additional
>>> information.
>>>
>>> It might be simpler to drop add_attributes and add all attributes
>>> unconditionally in this function instead.  If the user tries to specify the same
>>> attribute using both syntaxes, the pattern would end up with two definitions
>>> of the same attribute, which ought to be flagged by existing code.
>>>
>>
>> This was done to support the (in arm backend) common thing of having attributes
>> which are either too complex to add inline in the new syntax or that just repeat a
>> value.
>>
>> i.e. it's to allow cases like this:
>>
>>    [(set_attr "length")
>>     (set_attr "predicable" "yes")
>>     (set_attr "predicable_short_it")
>>     (set_attr "arch")
>>     (set (attr "type") (if_then_else (match_operand 2 "const_int_operand" "")
>> 		      (const_string "alu_imm")
>> 		      (const_string "alu_sreg")))
>>
>> Where your attrs contains:
>>
>>    {@ [cons: =0, 1, 2; attrs: length, predicable_short_it, arch]
> 
> Yeah, agree it needs to be possible to define things like "type"
> in this way.

You also want it for the case where every alternative takes the same 
value, eg the "predicable - yes" attr.

R.

> 
>> However you're right, I could simply say that you must omit the set_attr in attrs and just
>> merge the two lists?  I think that's what you were alluding to?
> 
> Yeah, that's right.  Or just concatenate them and rely on later
> error checking (which should give reasonable diagnostics).
> 
> Thanks,
> Richard


  reply	other threads:[~2023-06-06 16:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 16:30 [PATCH] RFC: " Tamar Christina
2023-04-21 17:18 ` Richard Sandiford
2023-04-24  8:33   ` Richard Sandiford
2023-05-16 13:56     ` Richard Earnshaw (lists)
2023-04-24  9:05   ` Tamar Christina
2023-04-24  9:37     ` Richard Sandiford
2023-06-05 13:51 ` [PATCH v2] machine descriptor: " Tamar Christina
2023-06-05 20:35 ` Richard Sandiford
2023-06-06  7:47   ` Richard Sandiford
2023-06-06 12:00   ` Tamar Christina
2023-06-06 12:49     ` Richard Sandiford
2023-06-06 16:13       ` Richard Earnshaw (lists) [this message]
2023-06-08  9:58         ` Tamar Christina
2023-06-08 10:12           ` Andreas Schwab
2023-06-08 10:29             ` Richard Earnshaw (lists)
2023-06-08 10:33               ` Richard Earnshaw (lists)
2023-06-08 14:24           ` Richard Sandiford
2023-06-08 16:49           ` Mikael Morin
2023-06-13 15:26             ` Tamar Christina
2023-06-14 19:41               ` Richard Sandiford
2023-06-15  6:24                 ` Richard Sandiford

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=dec5d001-d0cc-7d3d-00b3-00ef417d1e7b@arm.com \
    --to=richard.earnshaw@arm.com \
    --cc=Tamar.Christina@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nd@arm.com \
    --cc=richard.sandiford@arm.com \
    /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).