Skip to content

Commit 38fc453

Browse files
authored
[SPARC][Driver] Move feature mode selection to Arch/Sparc.cpp (#149652)
This is so that it's performed also for flang and not just for clang. This should fix #138494.
1 parent 4e35ae1 commit 38fc453

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
130130
return "";
131131
}
132132

133-
void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
133+
void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
134+
const ArgList &Args,
134135
std::vector<StringRef> &Features) {
135136
sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
136137
if (FloatABI == sparc::FloatABI::Soft)
@@ -150,11 +151,19 @@ void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
150151
Features.push_back("-popc");
151152
}
152153

154+
// Those OSes default to enabling VIS on 64-bit SPARC.
155+
// See also the corresponding code for external assemblers in
156+
// sparc::getSparcAsmModeForCPU().
157+
bool IsSparcV9ATarget =
158+
(Triple.getArch() == llvm::Triple::sparcv9) &&
159+
(Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
153160
if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
154161
if (A->getOption().matches(options::OPT_mvis))
155162
Features.push_back("+vis");
156163
else
157164
Features.push_back("-vis");
165+
} else if (IsSparcV9ATarget) {
166+
Features.push_back("+vis");
158167
}
159168

160169
if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ FloatABI getSparcFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
3131
std::string getSparcTargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
3232
const llvm::Triple &Triple);
3333

34-
void getSparcTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
34+
void getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
35+
const llvm::opt::ArgList &Args,
3536
std::vector<llvm::StringRef> &Features);
3637
const char *getSparcAsmModeForCPU(llvm::StringRef Name,
3738
const llvm::Triple &Triple);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,16 +2731,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
27312731
CmdArgs.push_back(MipsTargetFeature);
27322732
}
27332733

2734-
// Those OSes default to enabling VIS on 64-bit SPARC.
2735-
// See also the corresponding code for external assemblers in
2736-
// sparc::getSparcAsmModeForCPU().
2737-
bool IsSparcV9ATarget =
2738-
(C.getDefaultToolChain().getArch() == llvm::Triple::sparcv9) &&
2739-
(Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
2740-
if (IsSparcV9ATarget && SparcTargetFeatures.empty()) {
2741-
CmdArgs.push_back("-target-feature");
2742-
CmdArgs.push_back("+vis");
2743-
}
27442734
for (const char *Feature : SparcTargetFeatures) {
27452735
CmdArgs.push_back("-target-feature");
27462736
CmdArgs.push_back(Feature);

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
856856
case llvm::Triple::sparc:
857857
case llvm::Triple::sparcel:
858858
case llvm::Triple::sparcv9:
859-
sparc::getSparcTargetFeatures(D, Args, Features);
859+
sparc::getSparcTargetFeatures(D, Triple, Args, Features);
860860
break;
861861
case llvm::Triple::r600:
862862
case llvm::Triple::amdgcn:

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ void Flang::addTargetOptions(const ArgList &Args,
447447
// Add the target features.
448448
switch (TC.getArch()) {
449449
default:
450+
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
450451
break;
451452
case llvm::Triple::aarch64:
452453
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);

flang/test/Driver/target-cpu-features.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
! RUN: %flang --target=loongarch64-linux-gnu -c %s -### 2>&1 \
4545
! RUN: | FileCheck %s -check-prefix=CHECK-LOONGARCH64
4646

47+
! RUN: %flang --target=sparc64-linux-gnu -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS
48+
! RUN: %flang --target=sparc64-freebsd -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS
49+
! RUN: %flang --target=sparc64-openbsd -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS
50+
4751
! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"
4852
! CHECK-A57-SAME: "-target-cpu" "cortex-a57"
4953
! CHECK-A57-SAME: "-target-feature" "+v8a" "-target-feature" "+aes" "-target-feature" "+crc" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+perfmon" "-target-feature" "+sha2
@@ -92,3 +96,6 @@
9296

9397
! CHECK-LOONGARCH64: "-fc1" "-triple" "loongarch64-unknown-linux-gnu"
9498
! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
99+
100+
! CHECK-SPARC-VIS: "-fc1" "-triple" "sparc64-{{[^"]+}}"
101+
! CHECK-SPARC-VIS-SAME: "-target-feature" "+vis"

0 commit comments

Comments
 (0)