public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][i386] target: support spaces in target attribute.
@ 2021-10-04 15:11 Martin Liška
  2021-10-04 21:02 ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Liška @ 2021-10-04 15:11 UTC (permalink / raw)
  To: gcc-patches

Hello.

The patch is about supporting target attribute values like "no-avx, sse2   ".
I'm planning doing the same change for aarch64 and other archs as well once
this one is accepted.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR target/102374

gcc/ChangeLog:

	* config/i386/i386-options.c (ix86_valid_target_attribute_inner_p):
	* system.h (strip_spaces):

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr102374.c: New test.
---
  gcc/config/i386/i386-options.c           |  2 ++
  gcc/system.h                             | 21 +++++++++++++++++++++
  gcc/testsuite/gcc.target/i386/pr102374.c |  3 +++
  3 files changed, 26 insertions(+)
  create mode 100644 gcc/testsuite/gcc.target/i386/pr102374.c

diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index e7a3bd4aaea..c88bc77b04d 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1146,6 +1146,8 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
  	  next_optstr = NULL;
  	}
  
+      p = strip_spaces (p, &len);
+
        /* Recognize no-xxx.  */
        if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
  	{
diff --git a/gcc/system.h b/gcc/system.h
index adde3e264b6..35b15203a96 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1305,4 +1305,25 @@ startswith (const char *str, const char *prefix)
    return strncmp (str, prefix, strlen (prefix)) == 0;
  }
  
+/* Strip spaces from STRING with LEN length.
+   A stripped string is returned and LEN is updated accordingly.  */
+
+static inline char *
+strip_spaces (char *string, size_t *len)
+{
+  while (string[0] == ' ')
+    {
+      --(*len);
+      ++string;
+    }
+
+  while (string[*len - 1] == ' ')
+    {
+      string[*len - 1] = '\0';
+      --(*len);
+    }
+
+  return string;
+}
+
  #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/testsuite/gcc.target/i386/pr102374.c b/gcc/testsuite/gcc.target/i386/pr102374.c
new file mode 100644
index 00000000000..db84aeed9a5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102374.c
@@ -0,0 +1,3 @@
+/* PR target/102374 */
+
+void calculate_sse(void) __attribute__ ((__target__ ("no-avx, sse2   ")));
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][i386] target: support spaces in target attribute.
  2021-10-04 15:11 [PATCH][i386] target: support spaces in target attribute Martin Liška
@ 2021-10-04 21:02 ` Andrew Pinski
  2021-10-11 11:17   ` Martin Liška
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2021-10-04 21:02 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Mon, Oct 4, 2021 at 8:11 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> The patch is about supporting target attribute values like "no-avx, sse2   ".
> I'm planning doing the same change for aarch64 and other archs as well once
> this one is accepted.

It might be useful to skip tabs for the same reason as spaces really.

Thanks,
Andrew

>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>         PR target/102374
>
> gcc/ChangeLog:
>
>         * config/i386/i386-options.c (ix86_valid_target_attribute_inner_p):
>         * system.h (strip_spaces):
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr102374.c: New test.
> ---
>   gcc/config/i386/i386-options.c           |  2 ++
>   gcc/system.h                             | 21 +++++++++++++++++++++
>   gcc/testsuite/gcc.target/i386/pr102374.c |  3 +++
>   3 files changed, 26 insertions(+)
>   create mode 100644 gcc/testsuite/gcc.target/i386/pr102374.c
>
> diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
> index e7a3bd4aaea..c88bc77b04d 100644
> --- a/gcc/config/i386/i386-options.c
> +++ b/gcc/config/i386/i386-options.c
> @@ -1146,6 +1146,8 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
>           next_optstr = NULL;
>         }
>
> +      p = strip_spaces (p, &len);
> +
>         /* Recognize no-xxx.  */
>         if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
>         {
> diff --git a/gcc/system.h b/gcc/system.h
> index adde3e264b6..35b15203a96 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -1305,4 +1305,25 @@ startswith (const char *str, const char *prefix)
>     return strncmp (str, prefix, strlen (prefix)) == 0;
>   }
>
> +/* Strip spaces from STRING with LEN length.
> +   A stripped string is returned and LEN is updated accordingly.  */
> +
> +static inline char *
> +strip_spaces (char *string, size_t *len)
> +{
> +  while (string[0] == ' ')
> +    {
> +      --(*len);
> +      ++string;
> +    }
> +
> +  while (string[*len - 1] == ' ')
> +    {
> +      string[*len - 1] = '\0';
> +      --(*len);
> +    }
> +
> +  return string;
> +}
> +
>   #endif /* ! GCC_SYSTEM_H */
> diff --git a/gcc/testsuite/gcc.target/i386/pr102374.c b/gcc/testsuite/gcc.target/i386/pr102374.c
> new file mode 100644
> index 00000000000..db84aeed9a5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102374.c
> @@ -0,0 +1,3 @@
> +/* PR target/102374 */
> +
> +void calculate_sse(void) __attribute__ ((__target__ ("no-avx, sse2   ")));
> --
> 2.33.0
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][i386] target: support spaces in target attribute.
  2021-10-04 21:02 ` Andrew Pinski
@ 2021-10-11 11:17   ` Martin Liška
  2021-10-18 11:23     ` Martin Liška
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Liška @ 2021-10-11 11:17 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 138 bytes --]

On 10/4/21 23:02, Andrew Pinski wrote:
> It might be useful to skip tabs for the same reason as spaces really.

Sure, be my guest.

Martin

[-- Attachment #2: 0001-target-support-spaces-in-target-attribute.patch --]
[-- Type: text/x-patch, Size: 2244 bytes --]

From b66d7be2c1b3ac286257e3df4d9796e391751bef Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 4 Oct 2021 14:06:14 +0200
Subject: [PATCH] target: support spaces in target attribute.

	PR target/102374

gcc/ChangeLog:

	* config/i386/i386-options.c (ix86_valid_target_attribute_inner_p): Strip whitespaces.
	* system.h (strip_whilespaces): New function.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr102374.c: New test.
---
 gcc/config/i386/i386-options.c           |  2 ++
 gcc/system.h                             | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr102374.c |  3 +++
 3 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr102374.c

diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index e7a3bd4aaea..c9523b26f49 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1146,6 +1146,8 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
 	  next_optstr = NULL;
 	}
 
+      p = strip_whitespaces (p, &len);
+
       /* Recognize no-xxx.  */
       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
 	{
diff --git a/gcc/system.h b/gcc/system.h
index adde3e264b6..17a6a553b0b 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1305,4 +1305,25 @@ startswith (const char *str, const char *prefix)
   return strncmp (str, prefix, strlen (prefix)) == 0;
 }
 
+/* Strip white spaces from STRING with LEN length.
+   A stripped string is returned and LEN is updated accordingly.  */
+
+static inline char *
+strip_whitespaces (char *string, size_t *len)
+{
+  while (string[0] == ' ' || string[0] == '\t')
+    {
+      --(*len);
+      ++string;
+    }
+
+  while (string[*len - 1] == ' ' || string[*len - 1] == '\t')
+    {
+      string[*len - 1] = '\0';
+      --(*len);
+    }
+
+  return string;
+}
+
 #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/testsuite/gcc.target/i386/pr102374.c b/gcc/testsuite/gcc.target/i386/pr102374.c
new file mode 100644
index 00000000000..21aa76011ed
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102374.c
@@ -0,0 +1,3 @@
+/* PR target/102374 */
+
+void calculate_sse(void) __attribute__ ((__target__ ("	no-avx, sse2   ")));
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][i386] target: support spaces in target attribute.
  2021-10-11 11:17   ` Martin Liška
@ 2021-10-18 11:23     ` Martin Liška
  2021-10-18 15:12       ` Uros Bizjak
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Liška @ 2021-10-18 11:23 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: GCC Patches, Uros Bizjak, Hongtao Liu

On 10/11/21 13:17, Martin Liška wrote:
> On 10/4/21 23:02, Andrew Pinski wrote:
>> It might be useful to skip tabs for the same reason as spaces really.
> 
> Sure, be my guest.
> 
> Martin

May I please ping this i386-specific patch?

Thanks,
Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][i386] target: support spaces in target attribute.
  2021-10-18 11:23     ` Martin Liška
@ 2021-10-18 15:12       ` Uros Bizjak
  2021-10-19  6:49         ` Martin Liška
  0 siblings, 1 reply; 6+ messages in thread
From: Uros Bizjak @ 2021-10-18 15:12 UTC (permalink / raw)
  To: Martin Liška; +Cc: Andrew Pinski, GCC Patches, Hongtao Liu

On Mon, Oct 18, 2021 at 1:23 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/11/21 13:17, Martin Liška wrote:
> > On 10/4/21 23:02, Andrew Pinski wrote:
> >> It might be useful to skip tabs for the same reason as spaces really.
> >
> > Sure, be my guest.
> >
> > Martin
>
> May I please ping this i386-specific patch?

It is not i386-specific (due to system.h change). But one line in
i386-options.c is OK.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][i386] target: support spaces in target attribute.
  2021-10-18 15:12       ` Uros Bizjak
@ 2021-10-19  6:49         ` Martin Liška
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liška @ 2021-10-19  6:49 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: Andrew Pinski, GCC Patches, Hongtao Liu

On 10/18/21 17:12, Uros Bizjak wrote:
> On Mon, Oct 18, 2021 at 1:23 PM Martin Liška <mliska@suse.cz> wrote:
>>
>> On 10/11/21 13:17, Martin Liška wrote:
>>> On 10/4/21 23:02, Andrew Pinski wrote:
>>>> It might be useful to skip tabs for the same reason as spaces really.
>>>
>>> Sure, be my guest.
>>>
>>> Martin
>>
>> May I please ping this i386-specific patch?
> 
> It is not i386-specific (due to system.h change). But one line in
> i386-options.c is OK.
> 
> Thanks,
> Uros.
> 

Thanks. I bet the system.h bit is generally fine and I'm going to install the patch.

Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-19  6:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 15:11 [PATCH][i386] target: support spaces in target attribute Martin Liška
2021-10-04 21:02 ` Andrew Pinski
2021-10-11 11:17   ` Martin Liška
2021-10-18 11:23     ` Martin Liška
2021-10-18 15:12       ` Uros Bizjak
2021-10-19  6:49         ` Martin Liška

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