Skip to content

Commit 9123b7e

Browse files
committed
[Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64
While working on supporting PR llvm#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.
1 parent 43c9203 commit 9123b7e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Sparc.h"
10+
#include "clang/Driver/Distro.h"
1011
#include "clang/Driver/Driver.h"
1112
#include "clang/Driver/DriverDiagnostic.h"
1213
#include "clang/Driver/Options.h"
@@ -125,7 +126,9 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
125126
return std::string(CPUName);
126127
}
127128

128-
if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
129+
Distro Dist(D.getVFS(), Triple);
130+
if (Triple.getArch() == llvm::Triple::sparc &&
131+
(Triple.isOSSolaris() || Dist.IsDebian() || Dist.IsGentoo()))
129132
return "v9";
130133
return "";
131134
}

clang/test/Preprocessor/predefined-arch-macros.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,13 +4131,16 @@
41314131

41324132
// RUN: %clang -E -dM %s -o - 2>&1 \
41334133
// RUN: -target sparc-unknown-linux \
4134-
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC
4134+
// RUN: | FileCheck -match-full-lines %s -check-prefixes=CHECK_SPARC,CHECK_SPARC%if sparc64-distro %{_V9%} %else %{_V8%}
41354135
// CHECK_SPARC: #define __BIG_ENDIAN__ 1
41364136
// CHECK_SPARC: #define __sparc 1
41374137
// CHECK_SPARC: #define __sparc__ 1
41384138
// CHECK_SPARC-NOT: #define __sparcv9 1
41394139
// CHECK_SPARC-NOT: #define __sparcv9__ 1
4140-
// CHECK_SPARC: #define __sparcv8 1
4140+
// CHECK_SPARC_V8: #define __sparcv8 1
4141+
// CHECK_SPARC_V8-NOT: #define __sparc_v9__ 1
4142+
// CHECK_SPARC_V9: #define __sparc_v9__ 1
4143+
// CHECK_SPARC_V9-NOT: #define __sparcv8 1
41414144
// CHECK_SPARC-NOT: #define __sparcv9 1
41424145
// CHECK_SPARC-NOT: #define __sparcv9__ 1
41434146

clang/test/lit.cfg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ def have_host_clang_repl_cuda():
224224
"default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
225225
)
226226

227+
# clang -m32 defaults to -mcpu=v9 on Linux/sparc64 distros.
228+
if re.search(r"debian|gentoo", platform.version(), re.I):
229+
config.available_features.add("sparc64-distro")
230+
227231
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
228232
if platform.system() not in ["FreeBSD"]:
229233
config.available_features.add("crash-recovery")

0 commit comments

Comments
 (0)