From: Victor Do Nascimento <Victor.DoNascimento@arm.com>
To: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>,
gcc-patches@gcc.gnu.org, kyrylo.tkachov@arm.com,
Richard.Earnshaw@arm.com, richard.sandiford@arm.com
Subject: Re: [PATCH 6/6] aarch64: Add front-end argument type checking for target builtins
Date: Mon, 9 Oct 2023 14:12:00 +0100 [thread overview]
Message-ID: <7db67c4b-0ccb-087f-873b-c14ab1ca8f9d@arm.com> (raw)
In-Reply-To: <mptwmvyir7s.fsf@arm.com>
On 10/7/23 12:53, Richard Sandiford wrote:
> Richard Earnshaw <Richard.Earnshaw@foss.arm.com> writes:
>> On 03/10/2023 16:18, Victor Do Nascimento wrote:
>>> In implementing the ACLE read/write system register builtins it was
>>> observed that leaving argument type checking to be done at expand-time
>>> meant that poorly-formed function calls were being "fixed" by certain
>>> optimization passes, meaning bad code wasn't being properly picked up
>>> in checking.
>>>
>>> Example:
>>>
>>> const char *regname = "amcgcr_el0";
>>> long long a = __builtin_aarch64_rsr64 (regname);
>>>
>>> is reduced by the ccp1 pass to
>>>
>>> long long a = __builtin_aarch64_rsr64 ("amcgcr_el0");
>>>
>>> As these functions require an argument of STRING_CST type, there needs
>>> to be a check carried out by the front-end capable of picking this up.
>>>
>>> The introduced `check_general_builtin_call' function will be called by
>>> the TARGET_CHECK_BUILTIN_CALL hook whenever a call to a builtin
>>> belonging to the AARCH64_BUILTIN_GENERAL category is encountered,
>>> carrying out any appropriate checks associated with a particular
>>> builtin function code.
>>
>> Doesn't this prevent reasonable wrapping of the __builtin... names with
>> something more palatable? Eg:
>>
>> static inline __attribute__(("always_inline")) long long get_sysreg_ll
>> (const char *regname)
>> {
>> return __builtin_aarch64_rsr64 (regname);
>> }
>>
>> ...
>> long long x = get_sysreg_ll("amcgcr_el0");
>> ...
>
> I think it's case of picking your poison. If we didn't do this,
> and only checked later, then it's unlikely that GCC and Clang would
> be consistent about when a constant gets folded soon enough.
>
> But yeah, it means that the above would need to be a macro in C.
> Enlightened souls using C++ could instead do:
>
> template<const char *regname>
> long long get_sysreg_ll()
> {
> return __builtin_aarch64_rsr64(regname);
> }
>
> ... get_sysreg_ll<"amcgcr_el0">() ...
>
> Or at least I hope so. Might be nice to have a test for this.
>
> Thanks,
> Richard
As Richard Earnshaw mentioned, this does break the use of `static inline
__attribute__(("always_inline"))', something I had found out in my
testing. My chosen implementation was indeed, to quote Richard
Sandiford, a case of "picking your poison" to have things line up with
Clang and behaving consistently across optimization levels.
Relaxing the the use of `TARGET_CHECK_BUILTIN_CALL' meant optimizations
were letting too many things through. Example:
const char *regname = "amcgcr_el0";
long long a = __builtin_aarch64_rsr64 (regname);
gets folded to
long long a = __builtin_aarch64_rsr64 ("amcgcr_el0");
and compilation passes at -01 even though it fails at -O0.
I had, however, not given any thought to the use of a template as a
valid C++ alternative.
I will evaluate the use of templates and add tests accordingly.
Cheers,
Victor
next prev parent reply other threads:[~2023-10-09 13:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 15:18 [PATCH 0/6] aarch64: Add support for __arm_rsr and __arm_wsr ACLE function family Victor Do Nascimento
2023-10-03 15:18 ` [PATCH 1/6] aarch64: Sync system register information with Binutils Victor Do Nascimento
2023-10-05 11:42 ` Richard Earnshaw
2023-10-05 13:04 ` Victor Do Nascimento
2023-10-09 0:02 ` Ramana Radhakrishnan
2023-10-09 12:52 ` Victor Do Nascimento
2023-10-03 15:18 ` [PATCH 2/6] aarch64: Add support for aarch64-sys-regs.def Victor Do Nascimento
2023-10-05 12:03 ` Richard Earnshaw
2023-10-03 15:18 ` [PATCH 3/6] aarch64: Implement system register validation tools Victor Do Nascimento
2023-10-05 12:24 ` Richard Earnshaw
2023-10-03 15:18 ` [PATCH 4/6] aarch64: Add basic target_print_operand support for CONST_STRING Victor Do Nascimento
2023-10-05 12:26 ` Richard Earnshaw
2023-10-05 12:33 ` Richard Earnshaw
2023-10-05 12:47 ` Victor Do Nascimento
2023-10-03 15:18 ` [PATCH 5/6] aarch64: Implement system register r/w arm ACLE intrinsic functions Victor Do Nascimento
2023-10-05 12:40 ` Richard Earnshaw
2023-10-03 15:18 ` [PATCH 6/6] aarch64: Add front-end argument type checking for target builtins Victor Do Nascimento
2023-10-05 12:48 ` Richard Earnshaw
2023-10-07 11:53 ` Richard Sandiford
2023-10-09 13:12 ` Victor Do Nascimento [this message]
2023-10-10 11:20 ` Richard Earnshaw (lists)
2023-10-12 10:37 ` 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=7db67c4b-0ccb-087f-873b-c14ab1ca8f9d@arm.com \
--to=victor.donascimento@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=Richard.Earnshaw@foss.arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=kyrylo.tkachov@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).