diff --git a/gcc/config.gcc b/gcc/config.gcc
index 2cc5aeec9e4..3833bfa16a9 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -477,6 +477,7 @@ nvptx-*-*)
 	cpu_type=nvptx
 	c_target_objs="nvptx-c.o"
 	cxx_target_objs="nvptx-c.o"
+	extra_options="${extra_options} nvptx/nvptx-gen.opt"
 	;;
 or1k*-*-*)
 	cpu_type=or1k
diff --git a/gcc/config/nvptx/gen-copyright.sh b/gcc/config/nvptx/gen-copyright.sh
new file mode 100644
index 00000000000..79f48995acc
--- /dev/null
+++ b/gcc/config/nvptx/gen-copyright.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+style="$1"
+case $style in
+    opt)
+    ;;
+    c)
+	first=true
+    ;;
+    *)
+	echo "Unknown style: \"$style\""
+	exit 1
+	;;
+esac
+
+( cat <<EOF
+Copyright (C) 2022 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.
+EOF
+) | while read line; do
+    case $style in
+	opt)
+	    if [ "$line" = "" ]; then
+		echo ";"
+	    else
+		echo "; $line"
+	    fi
+	    ;;
+	c)
+	    if $first; then
+		echo "/* $line"
+		first=false
+	    else
+		if [ "$line" = "" ]; then
+		    echo
+		else
+		    echo "   $line"
+		fi
+	    fi
+	    ;;
+    esac
+done
+
+
+case $style in
+    c)
+	echo "*/"
+	;;
+esac
diff --git a/gcc/config/nvptx/gen-h.sh b/gcc/config/nvptx/gen-h.sh
new file mode 100644
index 00000000000..605f874055a
--- /dev/null
+++ b/gcc/config/nvptx/gen-h.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+nvptx_sm_def="$1/nvptx-sm.def"
+gen_copyright_sh="$1/gen-copyright.sh"
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+cat <<EOF
+/* -*- buffer-read-only: t -*-
+   Generated automatically by gen-h.sh from nvptx-sm.def.
+*/
+EOF
+
+# Separator.
+echo
+
+. $gen_copyright_sh c
+
+# Separator.
+echo
+
+for sm in $sms; do
+    cat <<EOF
+#define TARGET_SM$sm (ptx_isa_option >= PTX_ISA_SM$sm)
+EOF
+done
diff --git a/gcc/config/nvptx/gen-opt.sh b/gcc/config/nvptx/gen-opt.sh
new file mode 100644
index 00000000000..5248ed25090
--- /dev/null
+++ b/gcc/config/nvptx/gen-opt.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+nvptx_sm_def="$1/nvptx-sm.def"
+gen_copyright_sh="$1/gen-copyright.sh"
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+last=
+for sm in $sms; do
+    last="$sm"
+done
+
+cat <<EOF
+; -*- buffer-read-only: t -*-
+; Generated automatically by gen-opt.sh from nvptx-sm.def.
+EOF
+
+# Separator.
+echo
+
+. $gen_copyright_sh opt
+
+# Separator.
+echo
+
+cat <<EOF
+Enum
+Name(ptx_isa) Type(int)
+Known PTX ISA versions (for use with the -misa= option):
+EOF
+
+# Separator.
+echo
+
+for sm in $sms; do
+    cat <<EOF
+EnumValue
+Enum(ptx_isa) String(sm_$sm) Value(PTX_ISA_SM$sm)
+EOF
+
+    if [ "$sm" == "$last" ]; then
+	# Don't end with trailing empty line.
+	continue
+    fi
+
+    # Separator.
+    echo
+done
diff --git a/gcc/config/nvptx/nvptx-gen.h b/gcc/config/nvptx/nvptx-gen.h
new file mode 100644
index 00000000000..1d6f0db54c7
--- /dev/null
+++ b/gcc/config/nvptx/nvptx-gen.h
@@ -0,0 +1,29 @@
+/* -*- buffer-read-only: t -*-
+   Generated automatically by gen-h.sh from nvptx-sm.def.
+*/
+
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 3, or (at your option) any later
+   version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#define TARGET_SM30 (ptx_isa_option >= PTX_ISA_SM30)
+#define TARGET_SM35 (ptx_isa_option >= PTX_ISA_SM35)
+#define TARGET_SM53 (ptx_isa_option >= PTX_ISA_SM53)
+#define TARGET_SM70 (ptx_isa_option >= PTX_ISA_SM70)
+#define TARGET_SM75 (ptx_isa_option >= PTX_ISA_SM75)
+#define TARGET_SM80 (ptx_isa_option >= PTX_ISA_SM80)
diff --git a/gcc/config/nvptx/nvptx-gen.opt b/gcc/config/nvptx/nvptx-gen.opt
new file mode 100644
index 00000000000..b6d433e6292
--- /dev/null
+++ b/gcc/config/nvptx/nvptx-gen.opt
@@ -0,0 +1,42 @@
+; -*- buffer-read-only: t -*-
+; Generated automatically by gen-opt.sh from nvptx-sm.def.
+
+; Copyright (C) 2022 Free Software Foundation, Inc.
+;
+; This file is part of GCC.
+;
+; GCC is free software; you can redistribute it and/or modify it under
+; the terms of the GNU General Public License as published by the Free
+; Software Foundation; either version 3, or (at your option) any later
+; version.
+;
+; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+; for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with GCC; see the file COPYING3.  If not see
+; <http://www.gnu.org/licenses/>.
+
+Enum
+Name(ptx_isa) Type(int)
+Known PTX ISA versions (for use with the -misa= option):
+
+EnumValue
+Enum(ptx_isa) String(sm_30) Value(PTX_ISA_SM30)
+
+EnumValue
+Enum(ptx_isa) String(sm_35) Value(PTX_ISA_SM35)
+
+EnumValue
+Enum(ptx_isa) String(sm_53) Value(PTX_ISA_SM53)
+
+EnumValue
+Enum(ptx_isa) String(sm_70) Value(PTX_ISA_SM70)
+
+EnumValue
+Enum(ptx_isa) String(sm_75) Value(PTX_ISA_SM75)
+
+EnumValue
+Enum(ptx_isa) String(sm_80) Value(PTX_ISA_SM80)
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index edffd088b15..4ab412bc7d8 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -86,11 +86,7 @@
 #define Pmode (TARGET_ABI64 ? DImode : SImode)
 #define STACK_SIZE_MODE Pmode
 
-#define TARGET_SM35 (ptx_isa_option >= PTX_ISA_SM35)
-#define TARGET_SM53 (ptx_isa_option >= PTX_ISA_SM53)
-#define TARGET_SM70 (ptx_isa_option >= PTX_ISA_SM70)
-#define TARGET_SM75 (ptx_isa_option >= PTX_ISA_SM75)
-#define TARGET_SM80 (ptx_isa_option >= PTX_ISA_SM80)
+#include "nvptx-gen.h"
 
 #define TARGET_PTX_6_0 (ptx_version_option >= PTX_VERSION_6_0)
 #define TARGET_PTX_6_3 (ptx_version_option >= PTX_VERSION_6_3)
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index f555ad1d8bf..c83ceb3568b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -51,28 +51,6 @@ mgomp
 Target Mask(GOMP)
 Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
 
-Enum
-Name(ptx_isa) Type(int)
-Known PTX ISA versions (for use with the -misa= option):
-
-EnumValue
-Enum(ptx_isa) String(sm_30) Value(PTX_ISA_SM30)
-
-EnumValue
-Enum(ptx_isa) String(sm_35) Value(PTX_ISA_SM35)
-
-EnumValue
-Enum(ptx_isa) String(sm_53) Value(PTX_ISA_SM53)
-
-EnumValue
-Enum(ptx_isa) String(sm_70) Value(PTX_ISA_SM70)
-
-EnumValue
-Enum(ptx_isa) String(sm_75) Value(PTX_ISA_SM75)
-
-EnumValue
-Enum(ptx_isa) String(sm_80) Value(PTX_ISA_SM80)
-
 ; Default needs to be in sync with default in ASM_SPEC in nvptx.h.
 misa=
 Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM35)
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index b1707665a9f..f17fc9c19aa 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -13,4 +13,21 @@ mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 	  mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
 
+$(srcdir)/config/nvptx/nvptx.h: $(srcdir)/config/nvptx/nvptx-gen.h
+$(srcdir)/config/nvptx/nvptx-gen.h: s-nvptx-gen-h; @true
+s-nvptx-gen-h: $(srcdir)/config/nvptx/nvptx-sm.def
+	$(SHELL) $(srcdir)/config/nvptx/gen-h.sh "$(srcdir)/config/nvptx" \
+	  > tmp-nvptx-gen.h
+	$(SHELL) $(srcdir)/../move-if-change \
+	  tmp-nvptx-gen.h $(srcdir)/config/nvptx/nvptx-gen.h
+	$(STAMP) s-nvptx-gen-h
+
+$(srcdir)/config/nvptx/nvptx-gen.opt: s-nvptx-gen-opt; @true
+s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def
+	$(SHELL) $(srcdir)/config/nvptx/gen-opt.sh "$(srcdir)/config/nvptx" \
+	  > tmp-nvptx-gen.opt
+	$(SHELL) $(srcdir)/../move-if-change \
+	  tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
+	$(STAMP) s-nvptx-gen-opt
+
 MULTILIB_OPTIONS = mgomp
