[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

Rainer Orth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 28 01:07:23 PDT 2022


ro created this revision.
ro added reviewers: glaubitz, MaskRay, jrtc27.
ro added a project: clang.
Herald added subscribers: StephenFan, pengfei, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

This is the Debian/sparc64 equivalent of D86621 <https://reviews.llvm.org/D86621>: since that distro only supports SPARC V9 CPUs, it should default to `-mcpu=v9`, among others to allow inlining of atomics even in 32-bit code.

Tested on `sparc64-pc-linux-gnu`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`.

There's currently one issue, though: while this is the right thing for Debian/sparc64 (I don't think Debian/sparc which ran on non-V9 CPUs is supported any longer), it's wrong for current Linux distributions for 32-bit CPUs (LEON Linux AFAIK, there may be others).  While the driver can distringuish between Debian and non-Debian distributions for that, I've found no way to do so in the testsuite.  Thus, `clang/test/Preprocessor/predefined-arch-macros.c` currently `FAIL`s the `CHECK_SPARC` tests: it needs to check for `__sparc_v9__` on Debian, but keep `__sparcv8` on others.  Any suggestions on how to handle this?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130688

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp


Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Sparc.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -134,7 +135,8 @@
     return std::string(CPUName);
   }
 
-  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+  if (Triple.getArch() == llvm::Triple::sparc &&
+      (Triple.isOSSolaris() || Distro(D.getVFS(), Triple).IsDebian()))
     return "v9";
   return "";
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130688.448254.patch
Type: text/x-patch
Size: 769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220728/e0e07027/attachment.bin>


More information about the cfe-commits mailing list