[v2,1/4] options: Define TARGET_<NAME>_P and TARGET_<NAME>_OPTS_P macro for Mask and InverseMask

Message ID 20231010041305.9111-2-kito.cheng@sifive.com
State Unresolved
Headers
Series RISC-V target attribute |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Kito Cheng Oct. 10, 2023, 4:13 a.m. UTC
  We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
specified target_variable, however we may want to test with specific
gcc_options variable rather than target_variable.

Like RISC-V has defined lots of Mask with TargetVariable, which is not
easy to use, because that means we need to known which Mask are associate with
which TargetVariable, so take a gcc_options variable is a better interface
for such use case.

gcc/ChangeLog:

	* doc/options.texi (Mask): Document TARGET_<NAME>_P and
	TARGET_<NAME>_OPTS_P.
	(InverseMask): Ditto.
	* opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
	TARGET_<NAME>_OPTS_P macro.
	(InverseMask): Ditto.
---
 gcc/doc/options.texi | 23 ++++++++++++++++-------
 gcc/opth-gen.awk     | 13 ++++++++++++-
 2 files changed, 28 insertions(+), 8 deletions(-)
  

Comments

Jeff Law Oct. 10, 2023, 1:50 p.m. UTC | #1
On 10/9/23 22:13, Kito Cheng wrote:
> We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
> specified target_variable, however we may want to test with specific
> gcc_options variable rather than target_variable.
> 
> Like RISC-V has defined lots of Mask with TargetVariable, which is not
> easy to use, because that means we need to known which Mask are associate with
> which TargetVariable, so take a gcc_options variable is a better interface
> for such use case.
> 
> gcc/ChangeLog:
> 
> 	* doc/options.texi (Mask): Document TARGET_<NAME>_P and
> 	TARGET_<NAME>_OPTS_P.
> 	(InverseMask): Ditto.
> 	* opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
> 	TARGET_<NAME>_OPTS_P macro.
> 	(InverseMask): Ditto.
OK assuming it passes a build cycle on x86 or some other common target.

jeff
  
Kito Cheng Oct. 11, 2023, 9:20 p.m. UTC | #2
Thanks, committed, and just did one more check with x86 again, it
works as well, hope no more awk portable issue this time :P

On Tue, Oct 10, 2023 at 6:51 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 10/9/23 22:13, Kito Cheng wrote:
> > We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
> > specified target_variable, however we may want to test with specific
> > gcc_options variable rather than target_variable.
> >
> > Like RISC-V has defined lots of Mask with TargetVariable, which is not
> > easy to use, because that means we need to known which Mask are associate with
> > which TargetVariable, so take a gcc_options variable is a better interface
> > for such use case.
> >
> > gcc/ChangeLog:
> >
> >       * doc/options.texi (Mask): Document TARGET_<NAME>_P and
> >       TARGET_<NAME>_OPTS_P.
> >       (InverseMask): Ditto.
> >       * opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
> >       TARGET_<NAME>_OPTS_P macro.
> >       (InverseMask): Ditto.
> OK assuming it passes a build cycle on x86 or some other common target.
>
> jeff
  
juzhe.zhong@rivai.ai Oct. 11, 2023, 10:49 p.m. UTC | #3
../../../../gcc/gcc/config/riscv/riscv.cc:8142:18: error: ‘TARGET_MIN_VLEN_OPTS’ was not declared in this scope
   int min_vlen = TARGET_MIN_VLEN_OPTS (opts);





juzhe.zhong@rivai.ai
 
From: Kito Cheng
Date: 2023-10-12 05:20
To: Jeff Law
CC: Kito Cheng; gcc-patches; palmer; rdapp; juzhe.zhong
Subject: Re: [PATCH v2 1/4] options: Define TARGET_<NAME>_P and TARGET_<NAME>_OPTS_P macro for Mask and InverseMask
Thanks, committed, and just did one more check with x86 again, it
works as well, hope no more awk portable issue this time :P
 
On Tue, Oct 10, 2023 at 6:51 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 10/9/23 22:13, Kito Cheng wrote:
> > We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
> > specified target_variable, however we may want to test with specific
> > gcc_options variable rather than target_variable.
> >
> > Like RISC-V has defined lots of Mask with TargetVariable, which is not
> > easy to use, because that means we need to known which Mask are associate with
> > which TargetVariable, so take a gcc_options variable is a better interface
> > for such use case.
> >
> > gcc/ChangeLog:
> >
> >       * doc/options.texi (Mask): Document TARGET_<NAME>_P and
> >       TARGET_<NAME>_OPTS_P.
> >       (InverseMask): Ditto.
> >       * opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
> >       TARGET_<NAME>_OPTS_P macro.
> >       (InverseMask): Ditto.
> OK assuming it passes a build cycle on x86 or some other common target.
>
> jeff
  
Kito Cheng Oct. 11, 2023, 10:50 p.m. UTC | #4
Oh, my bad seem like that was in later patch, let me fix now

钟居哲 <juzhe.zhong@rivai.ai> 於 2023年10月11日 週三 15:49 寫道:

> ../../../../gcc/gcc/config/riscv/riscv.cc:8142:18: error:
> ‘TARGET_MIN_VLEN_OPTS’ was not declared in this scope
>    int min_vlen = TARGET_MIN_VLEN_OPTS (opts);
>
>
>
> ------------------------------
> juzhe.zhong@rivai.ai
>
>
> *From:* Kito Cheng <kito.cheng@gmail.com>
> *Date:* 2023-10-12 05:20
> *To:* Jeff Law <jeffreyalaw@gmail.com>
> *CC:* Kito Cheng <kito.cheng@sifive.com>; gcc-patches
> <gcc-patches@gcc.gnu.org>; palmer <palmer@dabbelt.com>; rdapp
> <rdapp@ventanamicro.com>; juzhe.zhong <juzhe.zhong@rivai.ai>
> *Subject:* Re: [PATCH v2 1/4] options: Define TARGET_<NAME>_P and
> TARGET_<NAME>_OPTS_P macro for Mask and InverseMask
> Thanks, committed, and just did one more check with x86 again, it
> works as well, hope no more awk portable issue this time :P
>
> On Tue, Oct 10, 2023 at 6:51 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
> >
> >
> >
> > On 10/9/23 22:13, Kito Cheng wrote:
> > > We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
> > > specified target_variable, however we may want to test with specific
> > > gcc_options variable rather than target_variable.
> > >
> > > Like RISC-V has defined lots of Mask with TargetVariable, which is not
> > > easy to use, because that means we need to known which Mask are
> associate with
> > > which TargetVariable, so take a gcc_options variable is a better
> interface
> > > for such use case.
> > >
> > > gcc/ChangeLog:
> > >
> > >       * doc/options.texi (Mask): Document TARGET_<NAME>_P and
> > >       TARGET_<NAME>_OPTS_P.
> > >       (InverseMask): Ditto.
> > >       * opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
> > >       TARGET_<NAME>_OPTS_P macro.
> > >       (InverseMask): Ditto.
> > OK assuming it passes a build cycle on x86 or some other common target.
> >
> > jeff
>
>
>
  
Kito Cheng Oct. 11, 2023, 11:23 p.m. UTC | #5
Fixed, sorry for disturbing trunk

On Wed, Oct 11, 2023 at 3:50 PM Kito Cheng <kito.cheng@gmail.com> wrote:
>
> Oh, my bad seem like that was in later patch, let me fix now
>
> 钟居哲 <juzhe.zhong@rivai.ai> 於 2023年10月11日 週三 15:49 寫道:
>>
>> ../../../../gcc/gcc/config/riscv/riscv.cc:8142:18: error: ‘TARGET_MIN_VLEN_OPTS’ was not declared in this scope
>>    int min_vlen = TARGET_MIN_VLEN_OPTS (opts);
>>
>>
>>
>> ________________________________
>> juzhe.zhong@rivai.ai
>>
>>
>> From: Kito Cheng
>> Date: 2023-10-12 05:20
>> To: Jeff Law
>> CC: Kito Cheng; gcc-patches; palmer; rdapp; juzhe.zhong
>> Subject: Re: [PATCH v2 1/4] options: Define TARGET_<NAME>_P and TARGET_<NAME>_OPTS_P macro for Mask and InverseMask
>> Thanks, committed, and just did one more check with x86 again, it
>> works as well, hope no more awk portable issue this time :P
>>
>> On Tue, Oct 10, 2023 at 6:51 AM Jeff Law <jeffreyalaw@gmail.com> wrote:
>> >
>> >
>> >
>> > On 10/9/23 22:13, Kito Cheng wrote:
>> > > We TARGET_<NAME>_P marcro to test a Mask and InverseMask with user
>> > > specified target_variable, however we may want to test with specific
>> > > gcc_options variable rather than target_variable.
>> > >
>> > > Like RISC-V has defined lots of Mask with TargetVariable, which is not
>> > > easy to use, because that means we need to known which Mask are associate with
>> > > which TargetVariable, so take a gcc_options variable is a better interface
>> > > for such use case.
>> > >
>> > > gcc/ChangeLog:
>> > >
>> > >       * doc/options.texi (Mask): Document TARGET_<NAME>_P and
>> > >       TARGET_<NAME>_OPTS_P.
>> > >       (InverseMask): Ditto.
>> > >       * opth-gen.awk (Mask): Generate TARGET_<NAME>_P and
>> > >       TARGET_<NAME>_OPTS_P macro.
>> > >       (InverseMask): Ditto.
>> > OK assuming it passes a build cycle on x86 or some other common target.
>> >
>> > jeff
>>
  

Patch

diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index 1f7c15b8eb4..715f0a1479c 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -404,18 +404,27 @@  You may also specify @code{Var} to select a variable other than
 The options-processing script will automatically allocate a unique bit
 for the option.  If the option is attached to @samp{target_flags} or @code{Var}
 which is defined by @code{TargetVariable},  the script will set the macro
-@code{MASK_@var{name}} to the appropriate bitmask.  It will also declare a 
-@code{TARGET_@var{name}} macro that has the value 1 when the option is active
-and 0 otherwise.  If you use @code{Var} to attach the option to a different variable
-which is not defined by @code{TargetVariable}, the bitmask macro with be
-called @code{OPTION_MASK_@var{name}}.
+@code{MASK_@var{name}} to the appropriate bitmask.  It will also declare a
+@code{TARGET_@var{name}}, @code{TARGET_@var{name}_P} and
+@code{TARGET_@var{name}_OPTS_P}: @code{TARGET_@var{name}} macros that has the
+value 1 when the option is active and 0 otherwise, @code{TARGET_@var{name}_P} is
+similar to @code{TARGET_@var{name}} but take an argument as @samp{target_flags}
+or @code{TargetVariable}, and @code{TARGET_@var{name}_OPTS_P} also similar to
+@code{TARGET_@var{name}} but take an argument as @code{gcc_options}.
+If you use @code{Var} to attach the option to a different variable which is not
+defined by @code{TargetVariable}, the bitmask macro with be called
+@code{OPTION_MASK_@var{name}}.
 
 @item InverseMask(@var{othername})
 @itemx InverseMask(@var{othername}, @var{thisname})
 The option is the inverse of another option that has the
 @code{Mask(@var{othername})} property.  If @var{thisname} is given,
-the options-processing script will declare a @code{TARGET_@var{thisname}}
-macro that is 1 when the option is active and 0 otherwise.
+the options-processing script will declare @code{TARGET_@var{thisname}},
+@code{TARGET_@var{name}_P} and @code{TARGET_@var{name}_OPTS_P} macros:
+@code{TARGET_@var{thisname}} is 1 when the option is active and 0 otherwise,
+@code{TARGET_@var{name}_P} is similar to @code{TARGET_@var{name}} but take an
+argument as @samp{target_flags}, and and @code{TARGET_@var{name}_OPTS_P} also
+similar to @code{TARGET_@var{name}} but take an argument as @code{gcc_options}.
 
 @item Enum(@var{name})
 The option's argument is a string from the set of strings associated
diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk
index c4398be2f3a..26551575d55 100644
--- a/gcc/opth-gen.awk
+++ b/gcc/opth-gen.awk
@@ -439,6 +439,10 @@  for (i = 0; i < n_target_vars; i++)
 	{
 		print "#define TARGET_" other_masks[i "," j] \
 		      " ((" target_vars[i] " & MASK_" other_masks[i "," j] ") != 0)"
+		print "#define TARGET_" other_masks[i "," j] "_P(" target_vars[i] ")" \
+		      " (((" target_vars[i] ") & MASK_" other_masks[i "," j] ") != 0)"
+		print "#define TARGET_" other_masks[i "," j] "_OPTS_P(opts)" \
+		      " (((opts->x_" target_vars[i] ") & MASK_" other_masks[i "," j] ") != 0)"
 	}
 }
 print ""
@@ -469,15 +473,22 @@  for (i = 0; i < n_opts; i++) {
 		      " ((" vname " & " mask original_name ") != 0)"
 		print "#define TARGET_" name "_P(" vname ")" \
 		      " (((" vname ") & " mask original_name ") != 0)"
+		print "#define TARGET_" name "_OPTS_P(opts)" \
+		      " (((opts->x_" vname ") & " mask original_name ") != 0)"
 		print "#define TARGET_EXPLICIT_" name "_P(opts)" \
 		      " ((opts->x_" vname "_explicit & " mask original_name ") != 0)"
 		print "#define SET_TARGET_" name "(opts) opts->x_" vname " |= " mask original_name
 	}
 }
 for (i = 0; i < n_extra_masks; i++) {
-	if (extra_mask_macros[extra_masks[i]] == 0)
+	if (extra_mask_macros[extra_masks[i]] == 0) {
 		print "#define TARGET_" extra_masks[i] \
 		      " ((target_flags & MASK_" extra_masks[i] ") != 0)"
+		print "#define TARGET_" extra_masks[i] "_P(target_flags)" \
+		      " (((target_flags) & " extra_masks[i] ") != 0)"
+		print "#define TARGET_" extra_masks[i] "_OPTS_P(opts)" \
+		      " (((opts->x_target_flags) & MASK_" extra_masks[i] ") != 0)"
+	}
 }
 print ""