public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] genconditions: Add support for targets without non-trivial insn conditions
@ 2022-05-04  8:20 Jakub Jelinek
  2022-05-04  8:57 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2022-05-04  8:20 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

Somebody complained on IRC that when writing a new backend one can get
an error while compiling build/gencondmd.cc.
The problem is that when host compiler is g++ 3 or later (or when
bootstrapping), we compile it with g++ -std=c++11 -pedantic and
the generated insn_conditions array contains pairs
{ "cond", __builtin_constant_p (cond) ? (int) (cond) : -1 },
where cond is some non-trivial instruction condition.  Now if a target
uses "" for all the conditions (admittedly unlikely for non-trivial
target), the initializer for insn_conditions[] is {} and that is
pedantically rejected because C++ doesn't support zero-sized arrays.

The following patch fixes that by adding an artificial termination
element and skips that during the walk.

Bootstrapped/regtested on x86_64-linux and i686-linux, no change in
generated insn-conditions.md with it.  Ok for trunk?

2022-05-04  Jakub Jelinek  <jakub@redhat.com>

	* genconditions.cc (write_conditions): Append a { nullptr, -1 }
	element at the end of insn_conditions.
	(write_writer): Use ARRAY_SIZE (insn_conditions) - 1 instead of
	ARRAY_SIZE (insn_conditions).

--- gcc/genconditions.cc.jj	2022-01-18 11:58:59.586981999 +0100
+++ gcc/genconditions.cc	2022-05-03 20:01:59.428065439 +0200
@@ -175,7 +175,7 @@ static const struct c_test insn_conditio
 
   traverse_c_tests (write_one_condition, 0);
 
-  puts ("\n};\n#endif /* gcc >= 3.0.1 */\n");
+  puts ("  { nullptr, -1 }\n};\n#endif /* gcc >= 3.0.1 */\n");
 }
 
 /* Emit code which will convert the C-format table to a
@@ -192,7 +192,7 @@ write_writer (void)
         "  const char *p;\n"
         "  puts (\"(define_conditions [\");\n"
 	"#if GCC_VERSION >= 3001\n"
-	"  for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n"
+	"  for (i = 0; i < ARRAY_SIZE (insn_conditions) - 1; i++)\n"
 	"    {\n"
 	"      printf (\"  (%d \\\"\", insn_conditions[i].value);\n"
 	"      for (p = insn_conditions[i].expr; *p; p++)\n"

	Jakub


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

* Re: [PATCH] genconditions: Add support for targets without non-trivial insn conditions
  2022-05-04  8:20 [PATCH] genconditions: Add support for targets without non-trivial insn conditions Jakub Jelinek
@ 2022-05-04  8:57 ` Richard Biener
  2022-05-04  9:33   ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-05-04  8:57 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, gcc-patches

On Wed, 4 May 2022, Jakub Jelinek wrote:

> Hi!
> 
> Somebody complained on IRC that when writing a new backend one can get
> an error while compiling build/gencondmd.cc.
> The problem is that when host compiler is g++ 3 or later (or when
> bootstrapping), we compile it with g++ -std=c++11 -pedantic and
> the generated insn_conditions array contains pairs
> { "cond", __builtin_constant_p (cond) ? (int) (cond) : -1 },
> where cond is some non-trivial instruction condition.  Now if a target
> uses "" for all the conditions (admittedly unlikely for non-trivial
> target), the initializer for insn_conditions[] is {} and that is
> pedantically rejected because C++ doesn't support zero-sized arrays.
> 
> The following patch fixes that by adding an artificial termination
> element and skips that during the walk.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, no change in
> generated insn-conditions.md with it.  Ok for trunk?

OK.

I wonder what the generated GCC_VERSION conditions are about ...

Richard.

> 2022-05-04  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* genconditions.cc (write_conditions): Append a { nullptr, -1 }
> 	element at the end of insn_conditions.
> 	(write_writer): Use ARRAY_SIZE (insn_conditions) - 1 instead of
> 	ARRAY_SIZE (insn_conditions).
> 
> --- gcc/genconditions.cc.jj	2022-01-18 11:58:59.586981999 +0100
> +++ gcc/genconditions.cc	2022-05-03 20:01:59.428065439 +0200
> @@ -175,7 +175,7 @@ static const struct c_test insn_conditio
>  
>    traverse_c_tests (write_one_condition, 0);
>  
> -  puts ("\n};\n#endif /* gcc >= 3.0.1 */\n");
> +  puts ("  { nullptr, -1 }\n};\n#endif /* gcc >= 3.0.1 */\n");
>  }
>  
>  /* Emit code which will convert the C-format table to a
> @@ -192,7 +192,7 @@ write_writer (void)
>          "  const char *p;\n"
>          "  puts (\"(define_conditions [\");\n"
>  	"#if GCC_VERSION >= 3001\n"
> -	"  for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n"
> +	"  for (i = 0; i < ARRAY_SIZE (insn_conditions) - 1; i++)\n"
>  	"    {\n"
>  	"      printf (\"  (%d \\\"\", insn_conditions[i].value);\n"
>  	"      for (p = insn_conditions[i].expr; *p; p++)\n"
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

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

* Re: [PATCH] genconditions: Add support for targets without non-trivial insn conditions
  2022-05-04  8:57 ` Richard Biener
@ 2022-05-04  9:33   ` Jakub Jelinek
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2022-05-04  9:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jeff Law, gcc-patches

On Wed, May 04, 2022 at 10:57:57AM +0200, Richard Biener wrote:
> On Wed, 4 May 2022, Jakub Jelinek wrote:
> 
> > Hi!
> > 
> > Somebody complained on IRC that when writing a new backend one can get
> > an error while compiling build/gencondmd.cc.
> > The problem is that when host compiler is g++ 3 or later (or when
> > bootstrapping), we compile it with g++ -std=c++11 -pedantic and
> > the generated insn_conditions array contains pairs
> > { "cond", __builtin_constant_p (cond) ? (int) (cond) : -1 },
> > where cond is some non-trivial instruction condition.  Now if a target
> > uses "" for all the conditions (admittedly unlikely for non-trivial
> > target), the initializer for insn_conditions[] is {} and that is
> > pedantically rejected because C++ doesn't support zero-sized arrays.
> > 
> > The following patch fixes that by adding an artificial termination
> > element and skips that during the walk.
> > 
> > Bootstrapped/regtested on x86_64-linux and i686-linux, no change in
> > generated insn-conditions.md with it.  Ok for trunk?
> 
> OK.
> 
> I wonder what the generated GCC_VERSION conditions are about ...

To determine if an insn condition is compile time constant or not.
If it is and e.g. it is always false, it can just omit the insn altogether,
etc.
See https://gcc.gnu.org/legacy-ml/gcc-patches/2006-01/msg00394.html
for more details.

	Jakub


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

end of thread, other threads:[~2022-05-04  9:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04  8:20 [PATCH] genconditions: Add support for targets without non-trivial insn conditions Jakub Jelinek
2022-05-04  8:57 ` Richard Biener
2022-05-04  9:33   ` Jakub Jelinek

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