public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7422] [nvptx] Add nvptx-sm.def
@ 2022-03-01  7:59 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2022-03-01  7:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7efe46935c5fce8db13e00aa6f4b0f1599b330e4

commit r12-7422-g7efe46935c5fce8db13e00aa6f4b0f1599b330e4
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Feb 25 11:47:12 2022 +0100

    [nvptx] Add nvptx-sm.def
    
    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.

Diff:
---
 gcc/config/nvptx/nvptx-c.cc   | 22 ++++++++++------------
 gcc/config/nvptx/nvptx-opts.h | 11 +++++------
 gcc/config/nvptx/nvptx-sm.def | 30 ++++++++++++++++++++++++++++++
 gcc/config/nvptx/nvptx.cc     | 36 ++++++++++++------------------------
 4 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/gcc/config/nvptx/nvptx-c.cc b/gcc/config/nvptx/nvptx-c.cc
index b2375fb5b16..02f75625064 100644
--- a/gcc/config/nvptx/nvptx-c.cc
+++ b/gcc/config/nvptx/nvptx-c.cc
@@ -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);
 }
 
diff --git a/gcc/config/nvptx/nvptx-opts.h b/gcc/config/nvptx/nvptx-opts.h
index 30852b6992c..86b433caae8 100644
--- a/gcc/config/nvptx/nvptx-opts.h
+++ b/gcc/config/nvptx/nvptx-opts.h
@@ -22,12 +22,11 @@
 
 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
index 00000000000..c552eb0c88b
--- /dev/null
+++ b/gcc/config/nvptx/nvptx-sm.def
@@ -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
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 7862a90a65a..f3179efa8d6 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -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 ();


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-01  7:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  7:59 [gcc r12-7422] [nvptx] Add nvptx-sm.def Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).