[clang] [Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64 (PR #109278)
Rainer Orth via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 06:52:20 PDT 2024
https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/109278
>From 9123b7eae524418d0a671ac2114ddea2b2cf9695 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Thu, 19 Sep 2024 14:46:54 +0200
Subject: [PATCH 1/2] [Driver][Sparc] Default to -mcpu=v9 for 32-bit
Linux/sparc64
While working on supporting PR #109101 on Linux/sparc64, I was reminded
that `clang -m32` still defaults to generating V8 code, although the 64-bit
kernel requires a V9 CPU.
This patch corrects that on V9-only distros (Debian, Gentoo).
Tested on `sparc64-unknown-linux-gnu`, `x86_64-pc-linux-gnu`,
`sparcv9-sun-solaris2.11`, and `amd64-pc-solaris2.11`.
A previous version of this patch was submitted as [[Driver][Sparc] Default
to -mcpu=v9 for SparcV8 on Linux](https://reviews.llvm.org/D130688), but
got stalled for 2+ years.
---
clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 5 ++++-
clang/test/Preprocessor/predefined-arch-macros.c | 7 +++++--
clang/test/lit.cfg.py | 4 ++++
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index f7f0a265fef68b..44eddc7603b4bd 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/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"
@@ -125,7 +126,9 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
return std::string(CPUName);
}
- if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+ Distro Dist(D.getVFS(), Triple);
+ if (Triple.getArch() == llvm::Triple::sparc &&
+ (Triple.isOSSolaris() || Dist.IsDebian() || Dist.IsGentoo()))
return "v9";
return "";
}
diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c
index a149c69ee0cdb2..2e576546b45c7a 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -4131,13 +4131,16 @@
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target sparc-unknown-linux \
-// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC
+// RUN: | FileCheck -match-full-lines %s -check-prefixes=CHECK_SPARC,CHECK_SPARC%if sparc64-distro %{_V9%} %else %{_V8%}
// CHECK_SPARC: #define __BIG_ENDIAN__ 1
// CHECK_SPARC: #define __sparc 1
// CHECK_SPARC: #define __sparc__ 1
// CHECK_SPARC-NOT: #define __sparcv9 1
// CHECK_SPARC-NOT: #define __sparcv9__ 1
-// CHECK_SPARC: #define __sparcv8 1
+// CHECK_SPARC_V8: #define __sparcv8 1
+// CHECK_SPARC_V8-NOT: #define __sparc_v9__ 1
+// CHECK_SPARC_V9: #define __sparc_v9__ 1
+// CHECK_SPARC_V9-NOT: #define __sparcv8 1
// CHECK_SPARC-NOT: #define __sparcv9 1
// CHECK_SPARC-NOT: #define __sparcv9__ 1
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 92a3361ce672e2..068975fac5a7a4 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -224,6 +224,10 @@ def have_host_clang_repl_cuda():
"default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
)
+# clang -m32 defaults to -mcpu=v9 on Linux/sparc64 distros.
+if re.search(r"debian|gentoo", platform.version(), re.I):
+ config.available_features.add("sparc64-distro")
+
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
if platform.system() not in ["FreeBSD"]:
config.available_features.add("crash-recovery")
>From 4ebd64071794920fa7a8def0d69c862e82a00474 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Fri, 20 Sep 2024 15:49:51 +0200
Subject: [PATCH 2/2] - Always default to `-mcpu=v9`. - Add ReleaseNotes entry.
---
clang/docs/ReleaseNotes.rst | 5 +++++
clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 4 +---
clang/test/Preprocessor/predefined-arch-macros.c | 8 +++-----
clang/test/lit.cfg.py | 4 ----
4 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd004228b679e4..578e66488b6ebc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -39,6 +39,11 @@ code bases.
- The ``le32`` and ``le64`` targets have been removed.
+- ``clang -m32`` defaults to ``-mcpu=v9`` on SPARC Linux now. Distros
+ still supporting SPARC V8 CPUs need to specify ``-mcpu=v8`` with a
+ `config file
+ <https://clang.llvm.org/docs/UsersManual.html#configuration-files>`_.
+
C/C++ Language Potentially Breaking Changes
-------------------------------------------
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 44eddc7603b4bd..55fbc8b30698b9 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "Sparc.h"
-#include "clang/Driver/Distro.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
@@ -126,9 +125,8 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
return std::string(CPUName);
}
- Distro Dist(D.getVFS(), Triple);
if (Triple.getArch() == llvm::Triple::sparc &&
- (Triple.isOSSolaris() || Dist.IsDebian() || Dist.IsGentoo()))
+ (Triple.isOSSolaris() || Triple.isOSLinux()))
return "v9";
return "";
}
diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c
index 2e576546b45c7a..35801e758cc58a 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -4131,16 +4131,14 @@
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target sparc-unknown-linux \
-// RUN: | FileCheck -match-full-lines %s -check-prefixes=CHECK_SPARC,CHECK_SPARC%if sparc64-distro %{_V9%} %else %{_V8%}
+// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC
// CHECK_SPARC: #define __BIG_ENDIAN__ 1
// CHECK_SPARC: #define __sparc 1
// CHECK_SPARC: #define __sparc__ 1
// CHECK_SPARC-NOT: #define __sparcv9 1
// CHECK_SPARC-NOT: #define __sparcv9__ 1
-// CHECK_SPARC_V8: #define __sparcv8 1
-// CHECK_SPARC_V8-NOT: #define __sparc_v9__ 1
-// CHECK_SPARC_V9: #define __sparc_v9__ 1
-// CHECK_SPARC_V9-NOT: #define __sparcv8 1
+// CHECK_SPARC: #define __sparc_v9__ 1
+// CHECK_SPARC-NOT: #define __sparcv8 1
// CHECK_SPARC-NOT: #define __sparcv9 1
// CHECK_SPARC-NOT: #define __sparcv9__ 1
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 068975fac5a7a4..92a3361ce672e2 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -224,10 +224,6 @@ def have_host_clang_repl_cuda():
"default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
)
-# clang -m32 defaults to -mcpu=v9 on Linux/sparc64 distros.
-if re.search(r"debian|gentoo", platform.version(), re.I):
- config.available_features.add("sparc64-distro")
-
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
if platform.system() not in ["FreeBSD"]:
config.available_features.add("crash-recovery")
More information about the cfe-commits
mailing list