Skip to content

Commit 0f23569

Browse files
authored
[Driver] Default to -mcpu=ultrasparc3 on Solaris/SPARC (#149990)
Prompted by PR #149652, this patch changes the Solaris/SPARC default to -mcpu, matching both the Oracle Studio 12.6 compilers and GCC 16: [[PATCH] Default to -mcpu=ultrasparc3 on Solaris/SPARC](https://gcc.gnu.org/pipermail/gcc-patches/2025-July/690191.html). This is equivalent to enabling the `vis2` feature. Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
1 parent 0b3579b commit 0f23569

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
2323
if (Triple.getArch() == llvm::Triple::sparcv9) {
2424
const char *DefV9CPU;
2525

26-
if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
26+
if (Triple.isOSSolaris())
27+
DefV9CPU = "-Av9b";
28+
else if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
2729
DefV9CPU = "-Av9a";
2830
else
2931
DefV9CPU = "-Av9";
@@ -157,6 +159,7 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
157159
bool IsSparcV9ATarget =
158160
(Triple.getArch() == llvm::Triple::sparcv9) &&
159161
(Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
162+
bool IsSparcV9BTarget = Triple.isOSSolaris();
160163
if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
161164
if (A->getOption().matches(options::OPT_mvis))
162165
Features.push_back("+vis");
@@ -171,6 +174,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
171174
Features.push_back("+vis2");
172175
else
173176
Features.push_back("-vis2");
177+
} else if (IsSparcV9BTarget) {
178+
Features.push_back("+vis2");
174179
}
175180

176181
if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {

clang/test/Driver/sparc-target-features.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
// RUN: %clang --target=sparc -mvis2 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
2222
// RUN: %clang --target=sparc -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
23+
/// Solaris/SPARC defaults to -mvis2
24+
// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
25+
// RUN: %clang --target=sparc-sun-solaris2.11 -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
26+
// RUN: %clang --target=sparcv9-sun-solaris2.11 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
27+
// RUN: %clang --target=sparcv9-sun-solaris2.11 -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
2328
// VIS2: "-target-feature" "+vis2"
2429
// NO-VIS2: "-target-feature" "-vis2"
2530

0 commit comments

Comments
 (0)