From fee2fbedbb43ad7a017a33ed2b820be79b75e7e5 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Mon, 22 Jul 2024 10:49:16 +0200
Subject: [PATCH] nvptx: Use 'enum ptx_version', 'enum ptx_isa' instead of
'int'
This allows getting rid of the respective type casts. No change in behavior
intended.
gcc/
* config/nvptx/gen-opt.sh: Use 'enum ptx_isa' instead of 'int'.
* config/nvptx/nvptx-gen.opt: Regenerate.
* config/nvptx/nvptx.opt: Use 'enum ptx_version' instead of 'int'.
* config/nvptx/nvptx-opts.h (enum ptx_isa): Add 'PTX_ISA_unset'.
(enum ptx_version): Add 'PTX_VERSION_unset'.
* config/nvptx/nvptx-c.cc (nvptx_cpu_cpp_builtins): Adjust.
* config/nvptx/nvptx.cc (default_ptx_version_option)
(handle_ptx_version_option, nvptx_option_override)
(nvptx_file_start): Likewise.
---
gcc/config/nvptx/gen-opt.sh | 14 +++++++++++++-
gcc/config/nvptx/nvptx-c.cc | 6 ++----
gcc/config/nvptx/nvptx-gen.opt | 2 +-
gcc/config/nvptx/nvptx-opts.h | 4 +++-
gcc/config/nvptx/nvptx.cc | 24 ++++++++++++------------
gcc/config/nvptx/nvptx.opt | 9 ++++++---
6 files changed, 37 insertions(+), 22 deletions(-)
@@ -38,12 +38,24 @@ echo
. $gen_copyright_sh opt
+# Not emitting the following here (in addition to having it in 'nvptx.opt'), as
+# we'll otherwise run into:
+#
+# gtyp-input.list:10: file [...]/gcc/config/nvptx/nvptx-opts.h specified more than once for language (all)
+# make[2]: *** [Makefile:2981: s-gtype] Error 1
+: ||
+cat <<EOF
+
+HeaderInclude
+config/nvptx/nvptx-opts.h
+EOF
+
# Separator.
echo
cat <<EOF
Enum
-Name(ptx_isa) Type(int)
+Name(ptx_isa) Type(enum ptx_isa)
Known PTX ISA target architectures (for use with the -misa= option):
EOF
@@ -51,10 +51,8 @@ nvptx_cpu_cpp_builtins (void)
cpp_define (parse_in, ptx_sm);
{
- unsigned major
- = ptx_version_to_number ((ptx_version)ptx_version_option, true);
- unsigned minor
- = ptx_version_to_number ((ptx_version)ptx_version_option, false);
+ unsigned major = ptx_version_to_number (ptx_version_option, true);
+ unsigned minor = ptx_version_to_number (ptx_version_option, false);
cpp_define_formatted (parse_in, "__PTX_ISA_VERSION_MAJOR__=%u", major);
cpp_define_formatted (parse_in, "__PTX_ISA_VERSION_MINOR__=%u", minor);
}
@@ -20,7 +20,7 @@
; <http://www.gnu.org/licenses/>.
Enum
-Name(ptx_isa) Type(int)
+Name(ptx_isa) Type(enum ptx_isa)
Known PTX ISA target architectures (for use with the -misa= option):
EnumValue
@@ -22,6 +22,7 @@
enum ptx_isa
{
+ PTX_ISA_unset,
#define NVPTX_SM(XX, SEP) PTX_ISA_SM ## XX SEP
#define NVPTX_SM_SEP ,
#include "nvptx-sm.def"
@@ -31,7 +32,8 @@ enum ptx_isa
enum ptx_version
{
- PTX_VERSION_default,
+ PTX_VERSION_unset,
+ PTX_VERSION_default = PTX_VERSION_unset,
PTX_VERSION_3_0,
PTX_VERSION_3_1,
PTX_VERSION_4_2,
@@ -231,8 +231,7 @@ first_ptx_version_supporting_sm (enum ptx_isa sm)
static enum ptx_version
default_ptx_version_option (void)
{
- enum ptx_version first
- = first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option);
+ enum ptx_version first = first_ptx_version_supporting_sm (ptx_isa_option);
/* Pick a version that supports the sm. */
enum ptx_version res = first;
@@ -311,20 +310,21 @@ sm_version_to_string (enum ptx_isa sm)
static void
handle_ptx_version_option (void)
{
- if (!OPTION_SET_P (ptx_version_option)
- || ptx_version_option == PTX_VERSION_default)
+ if (!OPTION_SET_P (ptx_version_option))
+ gcc_checking_assert (ptx_version_option == PTX_VERSION_default);
+
+ if (ptx_version_option == PTX_VERSION_default)
{
ptx_version_option = default_ptx_version_option ();
return;
}
- enum ptx_version first
- = first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option);
+ enum ptx_version first = first_ptx_version_supporting_sm (ptx_isa_option);
if (ptx_version_option < first)
error ("PTX version (%<-mptx%>) needs to be at least %s to support selected"
" %<-misa%> (sm_%s)", ptx_version_to_string (first),
- sm_version_to_string ((enum ptx_isa)ptx_isa_option));
+ sm_version_to_string (ptx_isa_option));
}
/* Implement TARGET_OPTION_OVERRIDE. */
@@ -336,7 +336,9 @@ nvptx_option_override (void)
/* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
line; but handle the case that the compiler is not run via the driver. */
- if (!OPTION_SET_P (ptx_isa_option))
+ gcc_checking_assert ((ptx_isa_option == PTX_ISA_unset)
+ == (!OPTION_SET_P (ptx_isa_option)));
+ if (ptx_isa_option == PTX_ISA_unset)
fatal_error (UNKNOWN_LOCATION, "%<-march=%> must be specified");
handle_ptx_version_option ();
@@ -5953,13 +5955,11 @@ nvptx_file_start (void)
fputs ("// BEGIN PREAMBLE\n", asm_out_file);
fputs ("\t.version\t", asm_out_file);
- fputs (ptx_version_to_string ((enum ptx_version)ptx_version_option),
- asm_out_file);
+ fputs (ptx_version_to_string (ptx_version_option), asm_out_file);
fputs ("\n", asm_out_file);
fputs ("\t.target\tsm_", asm_out_file);
- fputs (sm_version_to_string ((enum ptx_isa)ptx_isa_option),
- asm_out_file);
+ fputs (sm_version_to_string (ptx_isa_option), asm_out_file);
fputs ("\n", asm_out_file);
fprintf (asm_out_file, "\t.address_size %d\n", GET_MODE_BITSIZE (Pmode));
@@ -17,6 +17,9 @@
; along with GCC; see the file COPYING3. If not see
; <http://www.gnu.org/licenses/>.
+HeaderInclude
+config/nvptx/nvptx-opts.h
+
; It's not clear whether this was ever build/tested/used, so this is no longer
; exposed to the user.
;m32
@@ -53,7 +56,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_unset)
Specify the PTX ISA target architecture to use.
march=
@@ -118,7 +121,7 @@ march-map=sm_90a
Target RejectNegative Alias(misa=,sm_80)
Enum
-Name(ptx_version) Type(int)
+Name(ptx_version) Type(enum ptx_version)
Known PTX ISA versions (for use with the -mptx= option):
EnumValue
@@ -137,7 +140,7 @@ EnumValue
Enum(ptx_version) String(_) Value(PTX_VERSION_default)
mptx=
-Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option)
+Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option) Init(PTX_VERSION_unset)
Specify the PTX ISA version to use.
minit-regs=
--
2.34.1