From 1af83aa09979e5f2ca36f844d56ccd629268057d Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Sun, 10 Nov 2024 17:35:07 +0100
Subject: [PATCH] nvptx: Expose '-mptx=4.2'
'PTX_VERSION_4_2' was added in commit decde11183bdccc46587d6614b75f3d56a2f2e4a
"[nvptx] Choose -mptx default based on -misa" for use for '-march=sm_52'
('first_ptx_version_supporting_sm', 'PTX_ISA_SM53'), as documented by Nvidia.
However, '-mptx=4.2' wasn't exposed to the user, but there's no reason not to.
gcc/
* config/nvptx/nvptx.h (TARGET_PTX_4_2): New.
* config/nvptx/nvptx.opt (Enum(ptx_version)): Add 'EnumValue'
'4.2' for 'PTX_VERSION_4_2'.
* doc/invoke.texi (Nvidia PTX Options): Document '-mptx=4.2'.
gcc/testsuite/
* gcc.target/nvptx/mptx=4.2.c: New.
---
gcc/config/nvptx/nvptx.h | 1 +
gcc/config/nvptx/nvptx.opt | 3 +++
gcc/doc/invoke.texi | 10 +++++++---
gcc/testsuite/gcc.target/nvptx/mptx=4.2.c | 19 +++++++++++++++++++
4 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/nvptx/mptx=4.2.c
@@ -90,6 +90,7 @@
/* There are no 'TARGET_PTX_3_1' and smaller conditionals: our baseline is
PTX ISA Version 3.1. */
+#define TARGET_PTX_4_2 (ptx_version_option >= PTX_VERSION_4_2)
#define TARGET_PTX_6_0 (ptx_version_option >= PTX_VERSION_6_0)
#define TARGET_PTX_6_3 (ptx_version_option >= PTX_VERSION_6_3)
#define TARGET_PTX_7_0 (ptx_version_option >= PTX_VERSION_7_0)
@@ -127,6 +127,9 @@ Known PTX ISA versions (for use with the -mptx= option):
EnumValue
Enum(ptx_version) String(3.1) Value(PTX_VERSION_3_1)
+EnumValue
+Enum(ptx_version) String(4.2) Value(PTX_VERSION_4_2)
+
EnumValue
Enum(ptx_version) String(6.0) Value(PTX_VERSION_6_0)
@@ -30070,9 +30070,13 @@ capable. For instance, for @option{-march-map=sm_50} select
@opindex mptx
@item -mptx=@var{version-string}
-Generate code for the specified PTX ISA version (e.g.@: @samp{7.0}).
-Valid version strings include @samp{3.1}, @samp{6.0}, @samp{6.3}, and
-@samp{7.0}. The default PTX ISA version is 6.0, unless a higher
+Generate code for the specified PTX ISA version.
+Valid version strings are
+@samp{3.1},
+@samp{4.2},
+@samp{6.0}, @samp{6.3},
+and @samp{7.0}.
+The default PTX ISA version is 6.0, unless a higher
version is required for specified PTX ISA target architecture via
option @option{-march=}.
new file mode 100644
@@ -0,0 +1,19 @@
+/* { dg-do assemble } */
+/* { dg-options {-march=sm_30 -mptx=4.2} } */
+/* { dg-additional-options -save-temps } */
+/* { dg-final { scan-assembler-times {(?n)^ \.version 4\.2$} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)^ \.target sm_30$} 1 } } */
+
+#if __PTX_ISA_VERSION_MAJOR__ != 4
+#error wrong value for __PTX_ISA_VERSION_MAJOR__
+#endif
+
+#if __PTX_ISA_VERSION_MINOR__ != 2
+#error wrong value for __PTX_ISA_VERSION_MINOR__
+#endif
+
+#if __PTX_SM__ != 300
+#error wrong value for __PTX_SM__
+#endif
+
+int dummy;
--
2.34.1