]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[nvptx] Add nvptx-sm.def
authorTom de Vries <tdevries@suse.de>
Fri, 25 Feb 2022 10:47:12 +0000 (11:47 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 1 Mar 2022 07:58:35 +0000 (08:58 +0100)
Add a file gcc/config/nvptx/nvptx-sm.def that lists all sm_xx versions used in
the port, like so:
...
NVPTX_SM(30, NVPTX_SM_SEP)
NVPTX_SM(35, NVPTX_SM_SEP)
NVPTX_SM(53, NVPTX_SM_SEP)
NVPTX_SM(70, NVPTX_SM_SEP)
NVPTX_SM(75, NVPTX_SM_SEP)
NVPTX_SM(80,)
...
and use it in various places using a pattern:
...
  #define NVPTX_SM(XX, SEP) { ... }
  #include "nvptx-sm.def"
  #undef NVPTX_SM
...

Tested on nvptx.

gcc/ChangeLog:

2022-02-25  Tom de Vries  <tdevries@suse.de>

* config/nvptx/nvptx-sm.def: New file.
* config/nvptx/nvptx-c.cc (nvptx_cpu_cpp_builtins): Use nvptx-sm.def.
* config/nvptx/nvptx-opts.h (enum ptx_isa): Same.
* config/nvptx/nvptx.cc (sm_version_to_string)
(nvptx_omp_device_kind_arch_isa): Same.

gcc/config/nvptx/nvptx-c.cc
gcc/config/nvptx/nvptx-opts.h
gcc/config/nvptx/nvptx-sm.def [new file with mode: 0644]
gcc/config/nvptx/nvptx.cc

index b2375fb5b163a6cabb71bc634c5b19bec4c2ab71..02f756250646e7ea4ca3d5e1f53d4cc106bd779c 100644 (file)
@@ -39,17 +39,15 @@ nvptx_cpu_cpp_builtins (void)
     cpp_define (parse_in, "__nvptx_softstack__");
   if (TARGET_UNIFORM_SIMT)
     cpp_define (parse_in,"__nvptx_unisimt__");
-  if (TARGET_SM80)
-    cpp_define (parse_in, "__PTX_SM__=800");
-  else if (TARGET_SM75)
-    cpp_define (parse_in, "__PTX_SM__=750");
-  else if (TARGET_SM70)
-    cpp_define (parse_in, "__PTX_SM__=700");
-  else if (TARGET_SM53)
-    cpp_define (parse_in, "__PTX_SM__=530");
-  else if (TARGET_SM35)
-    cpp_define (parse_in, "__PTX_SM__=350");
-  else
-    cpp_define (parse_in,"__PTX_SM__=300");
+
+  const char *ptx_sm = NULL;
+#define NVPTX_SM(XX, SEP) \
+  {                                            \
+    if (TARGET_SM ## XX)                       \
+      ptx_sm = "__PTX_SM__=" #XX "0"; \
+  }
+#include "nvptx-sm.def"
+#undef NVPTX_SM
+  cpp_define (parse_in, ptx_sm);
 }
 
index 30852b6992ccc16ce6f8ca9d306c9912fe935eec..86b433caae8db9548e7e4db2a65cec97a36a0387 100644 (file)
 
 enum ptx_isa
 {
-  PTX_ISA_SM30,
-  PTX_ISA_SM35,
-  PTX_ISA_SM53,
-  PTX_ISA_SM70,
-  PTX_ISA_SM75,
-  PTX_ISA_SM80
+#define NVPTX_SM(XX, SEP) PTX_ISA_SM ## XX SEP
+#define NVPTX_SM_SEP ,
+#include "nvptx-sm.def"
+#undef NVPTX_SM_SEP
+#undef NVPTX_SM
 };
 
 enum ptx_version
diff --git a/gcc/config/nvptx/nvptx-sm.def b/gcc/config/nvptx/nvptx-sm.def
new file mode 100644 (file)
index 0000000..c552eb0
--- /dev/null
@@ -0,0 +1,30 @@
+/* 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/>.  */
+
+#ifndef NVPTX_SM_SEP
+#define NVPTX_SM_SEP
+#endif
+
+NVPTX_SM (30, NVPTX_SM_SEP)
+NVPTX_SM (35, NVPTX_SM_SEP)
+NVPTX_SM (53, NVPTX_SM_SEP)
+NVPTX_SM (70, NVPTX_SM_SEP)
+NVPTX_SM (75, NVPTX_SM_SEP)
+NVPTX_SM (80,)
+
+#undef NVPTX_SM_SEP
index 7862a90a65a7e5d8192f39b96bba599ce1f79eb9..f3179efa8d6cab32d1670155aa7aa22ea0b4ecde 100644 (file)
@@ -276,18 +276,11 @@ sm_version_to_string (enum ptx_isa sm)
 {
   switch (sm)
     {
-    case PTX_ISA_SM30:
-      return "30";
-    case PTX_ISA_SM35:
-      return "35";
-    case PTX_ISA_SM53:
-      return "53";
-    case PTX_ISA_SM70:
-      return "70";
-    case PTX_ISA_SM75:
-      return "75";
-    case PTX_ISA_SM80:
-      return "80";
+#define NVPTX_SM(XX, SEP)                      \
+      case PTX_ISA_SM ## XX:                   \
+       return #XX;
+#include "nvptx-sm.def"
+#undef NVPTX_SM
     default:
       gcc_unreachable ();
     }
@@ -6177,18 +6170,13 @@ nvptx_omp_device_kind_arch_isa (enum omp_device_kind_arch_isa trait,
     case omp_device_arch:
       return strcmp (name, "nvptx") == 0;
     case omp_device_isa:
-      if (strcmp (name, "sm_30") == 0)
-       return !TARGET_SM35;
-      if (strcmp (name, "sm_35") == 0)
-       return TARGET_SM35 && !TARGET_SM53;
-      if (strcmp (name, "sm_53") == 0)
-       return TARGET_SM53 && !TARGET_SM70;
-      if (strcmp (name, "sm_70") == 0)
-       return TARGET_SM70 && !TARGET_SM75;
-      if (strcmp (name, "sm_75") == 0)
-       return TARGET_SM75 && !TARGET_SM80;
-      if (strcmp (name, "sm_80") == 0)
-       return TARGET_SM80;
+#define NVPTX_SM(XX, SEP)                              \
+      {                                                        \
+       if (strcmp (name, "sm_" #XX) == 0)              \
+         return ptx_isa_option == PTX_ISA_SM ## XX;    \
+      }
+#include "nvptx-sm.def"
+#undef NVPTX_SM
       return 0;
     default:
       gcc_unreachable ();