[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

Sean Perry via cfe-commits cfe-commits at lists.llvm.org
Fri May 31 10:56:36 PDT 2024


https://github.com/perry-ca updated https://github.com/llvm/llvm-project/pull/89854

>From 85da4a229ddeeb6c86ecfb0ba19ac921494a2b40 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Tue, 23 Apr 2024 20:16:15 -0500
Subject: [PATCH 1/3] Set the default arch for z/OS to be arch10

---
 clang/CMakeLists.txt                             |  2 ++
 clang/include/clang/Config/config.h.cmake        |  3 +++
 clang/lib/Basic/Targets/SystemZ.h                |  7 +++----
 clang/lib/Driver/ToolChains/Arch/SystemZ.cpp     |  5 ++++-
 clang/lib/Driver/ToolChains/Arch/SystemZ.h       |  3 ++-
 clang/lib/Driver/ToolChains/CommonArgs.cpp       |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp              |  3 ++-
 clang/test/Preprocessor/predefined-arch-macros.c | 16 ++++++++++++++++
 8 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index f092766fa19f0..f06fbec1d02f9 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -270,6 +270,8 @@ set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
 
 set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
 
+set(CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "zEC12" CACHE STRING "SystemZ z/OS Default Arch")
+
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 
diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake
index 27ed69e21562b..004c5c95c00cf 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -32,6 +32,9 @@
 /* Default architecture for SystemZ. */
 #define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
 
+/* Default architecture for SystemZ for z/OS. */
+#define CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "${CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH}"
+
 /* Multilib basename for libdir. */
 #define CLANG_INSTALL_LIBDIR_BASENAME "${CLANG_INSTALL_LIBDIR_BASENAME}"
 
diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h
index 8e302acd51b8a..45fb7e447b642 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -24,7 +24,6 @@ namespace targets {
 class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
 
   static const char *const GCCRegNames[];
-  std::string CPU;
   int ISARevision;
   bool HasTransactionalExecution;
   bool HasVector;
@@ -33,7 +32,8 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
 
 public:
   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
-      : TargetInfo(Triple), CPU("z10"), ISARevision(8),
+      : TargetInfo(Triple),
+        ISARevision(getISARevision(Triple.isOSzOS() ? "zEC12" : "z10")),
         HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
         UnalignedSymbols(false) {
     IntMaxType = SignedLong;
@@ -140,8 +140,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
   }
 
   bool setCPU(const std::string &Name) override {
-    CPU = Name;
-    ISARevision = getISARevision(CPU);
+    ISARevision = getISARevision(Name);
     return ISARevision != -1;
   }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
index 2213f431eb811..7baeffc00053a 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
@@ -34,7 +34,8 @@ systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
   return ABI;
 }
 
-std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
+std::string systemz::getSystemZTargetCPU(const Driver &, const ArgList &Args,
+                                         const llvm::Triple &T) {
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
     llvm::StringRef CPUName = A->getValue();
 
@@ -48,6 +49,8 @@ std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
 
     return std::string(CPUName);
   }
+  if (T.isOSzOS())
+    return CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH;
   return CLANG_SYSTEMZ_DEFAULT_ARCH;
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.h b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
index 1e42b68a8f3c2..438dab8765bc3 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.h
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
@@ -27,7 +27,8 @@ enum class FloatABI {
 
 FloatABI getSystemZFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
-std::string getSystemZTargetCPU(const llvm::opt::ArgList &Args);
+std::string getSystemZTargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
+                                const llvm::Triple &T);
 
 void getSystemZTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
                               std::vector<llvm::StringRef> &Features);
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b65b96db16bd7..73f5abfaafcba 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -604,7 +604,7 @@ std::string tools::getCPUName(const Driver &D, const ArgList &Args,
     return getLanaiTargetCPU(Args);
 
   case llvm::Triple::systemz:
-    return systemz::getSystemZTargetCPU(Args);
+    return systemz::getSystemZTargetCPU(D, Args, T);
 
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index f55b8bf48c13f..149f4060f4fc7 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -936,7 +936,8 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
   case llvm::Triple::systemz: {
     // Always pass an -march option, since our default of z10 is later
     // than the GNU assembler's default.
-    std::string CPUName = systemz::getSystemZTargetCPU(Args);
+    std::string CPUName =
+        systemz::getSystemZTargetCPU(D, Args, getToolChain().getTriple());
     CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
     break;
   }
diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c
index ca51f2fc22c51..55a6cf63a94e1 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -4153,6 +4153,20 @@
 
 // Begin SystemZ/GCC/Linux tests ----------------
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN:     -target s390x-ibm-zos \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SYSTEMZ_ZOS
+// CHECK_SYSTEMZ_ZOS: #define __ARCH__ 10
+// CHECK_SYSTEMZ_ZOS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_SYSTEMZ_ZOS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_SYSTEMZ_ZOS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_SYSTEMZ_ZOS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+// CHECK_SYSTEMZ_ZOS: #define __HTM__ 1
+// CHECK_SYSTEMZ_ZOS: #define __LONG_DOUBLE_128__ 1
+// CHECK_SYSTEMZ_ZOS: #define __s390__ 1
+// CHECK_SYSTEMZ_ZOS: #define __s390x__ 1
+// CHECK_SYSTEMZ_ZOS: #define __zarch__ 1
+
 // RUN: %clang -march=arch8 -E -dM %s -o - 2>&1 \
 // RUN:     -target s390x-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SYSTEMZ_ARCH8
@@ -4164,6 +4178,7 @@
 // CHECK_SYSTEMZ_ARCH8: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // CHECK_SYSTEMZ_ARCH8: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
 // CHECK_SYSTEMZ_ARCH8: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+// CHECK_SYSTEMZ_ARCH8-NOT: #define __HTM__ 1
 // CHECK_SYSTEMZ_ARCH8: #define __LONG_DOUBLE_128__ 1
 // CHECK_SYSTEMZ_ARCH8: #define __s390__ 1
 // CHECK_SYSTEMZ_ARCH8: #define __s390x__ 1
@@ -4180,6 +4195,7 @@
 // CHECK_SYSTEMZ_ARCH9: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // CHECK_SYSTEMZ_ARCH9: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
 // CHECK_SYSTEMZ_ARCH9: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+// CHECK_SYSTEMZ_ARCH9-NOT: #define __HTM__ 1
 // CHECK_SYSTEMZ_ARCH9: #define __LONG_DOUBLE_128__ 1
 // CHECK_SYSTEMZ_ARCH9: #define __s390__ 1
 // CHECK_SYSTEMZ_ARCH9: #define __s390x__ 1

>From d30d5e39d14e4a648e4ff4ebf025cd28b0d3d46d Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Fri, 17 May 2024 08:53:44 -0500
Subject: [PATCH 2/3] rework changes

---
 clang/CMakeLists.txt                         | 2 --
 clang/include/clang/Config/config.h.cmake    | 3 ---
 clang/lib/Basic/Targets.cpp                  | 2 ++
 clang/lib/Basic/Targets/SystemZ.cpp          | 2 ++
 clang/lib/Basic/Targets/SystemZ.h            | 2 +-
 clang/lib/Driver/ToolChains/Arch/SystemZ.cpp | 4 ++--
 clang/lib/Driver/ToolChains/Arch/SystemZ.h   | 2 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp   | 2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp          | 2 +-
 9 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index e045fc82aef53..c20ce47a12abb 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -274,8 +274,6 @@ set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
 
 set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
 
-set(CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "zEC12" CACHE STRING "SystemZ z/OS Default Arch")
-
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 
diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake
index 004c5c95c00cf..27ed69e21562b 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -32,9 +32,6 @@
 /* Default architecture for SystemZ. */
 #define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
 
-/* Default architecture for SystemZ for z/OS. */
-#define CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "${CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH}"
-
 /* Multilib basename for libdir. */
 #define CLANG_INSTALL_LIBDIR_BASENAME "${CLANG_INSTALL_LIBDIR_BASENAME}"
 
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index dc1792b3471e6..6707dc32ee5f5 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -11,6 +11,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/Config/config.h"
+
 #include "Targets.h"
 
 #include "Targets/AArch64.h"
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd4..01d74007c1ba3 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -10,6 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/Config/config.h"
+
 #include "SystemZ.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/LangOptions.h"
diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h
index a8404829f77a5..6b358926d0110 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -33,7 +33,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
 public:
   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
       : TargetInfo(Triple),
-        ISARevision(getISARevision(Triple.isOSzOS() ? "zEC12" : "z10")),
+        ISARevision(getISARevision(CLANG_SYSTEMZ_DEFAULT_ARCH)),
         HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
         UnalignedSymbols(false) {
     IntMaxType = SignedLong;
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
index 7baeffc00053a..574092c3e215d 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
@@ -34,7 +34,7 @@ systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
   return ABI;
 }
 
-std::string systemz::getSystemZTargetCPU(const Driver &, const ArgList &Args,
+std::string systemz::getSystemZTargetCPU(const ArgList &Args,
                                          const llvm::Triple &T) {
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
     llvm::StringRef CPUName = A->getValue();
@@ -50,7 +50,7 @@ std::string systemz::getSystemZTargetCPU(const Driver &, const ArgList &Args,
     return std::string(CPUName);
   }
   if (T.isOSzOS())
-    return CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH;
+    return "zEC12";
   return CLANG_SYSTEMZ_DEFAULT_ARCH;
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.h b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
index 438dab8765bc3..f2d30d24ba63c 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.h
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
@@ -27,7 +27,7 @@ enum class FloatABI {
 
 FloatABI getSystemZFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
-std::string getSystemZTargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
+std::string getSystemZTargetCPU(const llvm::opt::ArgList &Args,
                                 const llvm::Triple &T);
 
 void getSystemZTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 9dd974ba52909..14a478a0b8d94 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -604,7 +604,7 @@ std::string tools::getCPUName(const Driver &D, const ArgList &Args,
     return getLanaiTargetCPU(Args);
 
   case llvm::Triple::systemz:
-    return systemz::getSystemZTargetCPU(D, Args, T);
+    return systemz::getSystemZTargetCPU(Args, T);
 
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index f239a329141fd..45ab7ef9e0e33 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -937,7 +937,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
     // Always pass an -march option, since our default of z10 is later
     // than the GNU assembler's default.
     std::string CPUName =
-        systemz::getSystemZTargetCPU(D, Args, getToolChain().getTriple());
+        systemz::getSystemZTargetCPU(Args, getToolChain().getTriple());
     CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
     break;
   }

>From fe5ad9c1bc0b1c0d60451f017d7ec7a8233aaf26 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Fri, 31 May 2024 12:56:15 -0500
Subject: [PATCH 3/3] don't create new use of CMAKE macro

---
 clang/lib/Basic/Targets.cpp         | 2 --
 clang/lib/Basic/Targets/SystemZ.cpp | 2 --
 clang/lib/Basic/Targets/SystemZ.h   | 2 +-
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 6707dc32ee5f5..dc1792b3471e6 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -11,8 +11,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Config/config.h"
-
 #include "Targets.h"
 
 #include "Targets/AArch64.h"
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp b/clang/lib/Basic/Targets/SystemZ.cpp
index 01d74007c1ba3..06f08db2eadd4 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -10,8 +10,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Config/config.h"
-
 #include "SystemZ.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/LangOptions.h"
diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h
index 6b358926d0110..15df4f3df6353 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -33,7 +33,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
 public:
   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
       : TargetInfo(Triple),
-        ISARevision(getISARevision(CLANG_SYSTEMZ_DEFAULT_ARCH)),
+        ISARevision(getISARevision("z10")),
         HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
         UnalignedSymbols(false) {
     IntMaxType = SignedLong;



More information about the cfe-commits mailing list