Skip to content

[SPARC][Driver] Move feature mode selection to Arch/Sparc.cpp #149652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion clang/lib/Driver/ToolChains/Arch/Sparc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
return "";
}

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

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

if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Arch/Sparc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ FloatABI getSparcFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
std::string getSparcTargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);

void getSparcTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
void getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args,
std::vector<llvm::StringRef> &Features);
const char *getSparcAsmModeForCPU(llvm::StringRef Name,
const llvm::Triple &Triple);
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2731,16 +2731,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
CmdArgs.push_back(MipsTargetFeature);
}

// Those OSes default to enabling VIS on 64-bit SPARC.
// See also the corresponding code for external assemblers in
// sparc::getSparcAsmModeForCPU().
bool IsSparcV9ATarget =
(C.getDefaultToolChain().getArch() == llvm::Triple::sparcv9) &&
(Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
if (IsSparcV9ATarget && SparcTargetFeatures.empty()) {
CmdArgs.push_back("-target-feature");
CmdArgs.push_back("+vis");
}
for (const char *Feature : SparcTargetFeatures) {
CmdArgs.push_back("-target-feature");
CmdArgs.push_back(Feature);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
case llvm::Triple::sparc:
case llvm::Triple::sparcel:
case llvm::Triple::sparcv9:
sparc::getSparcTargetFeatures(D, Args, Features);
sparc::getSparcTargetFeatures(D, Triple, Args, Features);
break;
case llvm::Triple::r600:
case llvm::Triple::amdgcn:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ void Flang::addTargetOptions(const ArgList &Args,
// Add the target features.
switch (TC.getArch()) {
default:
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
break;
case llvm::Triple::aarch64:
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Driver/target-cpu-features.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
! RUN: %flang --target=loongarch64-linux-gnu -c %s -### 2>&1 \
! RUN: | FileCheck %s -check-prefix=CHECK-LOONGARCH64

! RUN: %flang --target=sparc64-linux-gnu -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS
! RUN: %flang --target=sparc64-freebsd -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS
! RUN: %flang --target=sparc64-openbsd -c -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SPARC-VIS

! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! CHECK-A57-SAME: "-target-cpu" "cortex-a57"
! 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
Expand Down Expand Up @@ -92,3 +96,6 @@

! CHECK-LOONGARCH64: "-fc1" "-triple" "loongarch64-unknown-linux-gnu"
! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"

! CHECK-SPARC-VIS: "-fc1" "-triple" "sparc64-{{[^"]+}}"
! CHECK-SPARC-VIS-SAME: "-target-feature" "+vis"