[llvm] b86440e - [CSKY] Fix the conflict of default fpu features and -mfpu option
Zi Xuan Wu via llvm-commits
llvm-commits at lists.llvm.org
Sun May 22 19:45:15 PDT 2022
Author: Zi Xuan Wu (Zeson)
Date: 2022-05-23T10:44:55+08:00
New Revision: b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9
URL: https://github.com/llvm/llvm-project/commit/b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9
DIFF: https://github.com/llvm/llvm-project/commit/b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9.diff
LOG: [CSKY] Fix the conflict of default fpu features and -mfpu option
The arch or cpu has its default fpu features and versions such as fpuv2_sf/fpuv3_sf.
And there is also -mfpu option to specify and override fpu version and features.
For example, C860 has fpuv3_sf/fpuv3_df feature as default, when
-mfpu=fpv2 is given, fpuv3_sf/fpuv3_df is replaced with fpuv2_sf/fpuv2_df.
Added:
clang/test/Driver/csky-mfpu.c
Modified:
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/CSKY.h
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
llvm/lib/Support/CSKYTargetParser.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/CSKY.cpp b/clang/lib/Basic/Targets/CSKY.cpp
index 40004da982594..adcffd90ae780 100644
--- a/clang/lib/Basic/Targets/CSKY.cpp
+++ b/clang/lib/Basic/Targets/CSKY.cpp
@@ -95,17 +95,36 @@ void CSKYTargetInfo::getTargetDefines(const LangOptions &Opts,
}
}
+bool CSKYTargetInfo::hasFeature(StringRef Feature) const {
+ return llvm::StringSwitch<bool>(Feature)
+ .Case("hard-float", HardFloat)
+ .Case("hard-float-abi", HardFloatABI)
+ .Case("fpuv2_sf", FPUV2_SF)
+ .Case("fpuv2_df", FPUV2_DF)
+ .Case("fpuv3_sf", FPUV3_SF)
+ .Case("fpuv3_df", FPUV3_DF)
+ .Case("vdspv2", VDSPV2)
+ .Case("dspv2", DSPV2)
+ .Case("vdspv1", VDSPV1)
+ .Case("3e3r1", is3E3R1)
+ .Default(false);
+}
+
bool CSKYTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) {
- HardFloat = false;
- VDSPV2 = false;
- VDSPV1 = false;
- DSPV2 = false;
- is3E3R1 = false;
-
for (const auto &Feature : Features) {
if (Feature == "+hard-float")
HardFloat = true;
+ if (Feature == "+hard-float-abi")
+ HardFloatABI = true;
+ if (Feature == "+fpuv2_sf")
+ FPUV2_SF = true;
+ if (Feature == "+fpuv2_df")
+ FPUV2_DF = true;
+ if (Feature == "+fpuv3_sf")
+ FPUV3_SF = true;
+ if (Feature == "+fpuv3_df")
+ FPUV3_DF = true;
if (Feature == "+vdspv2")
VDSPV2 = true;
if (Feature == "+dspv2")
diff --git a/clang/lib/Basic/Targets/CSKY.h b/clang/lib/Basic/Targets/CSKY.h
index 17e5f30d3cd87..7e932e7c86b1c 100644
--- a/clang/lib/Basic/Targets/CSKY.h
+++ b/clang/lib/Basic/Targets/CSKY.h
@@ -26,11 +26,16 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {
llvm::CSKY::ArchKind Arch = llvm::CSKY::ArchKind::INVALID;
std::string CPU;
- bool HardFloat;
- bool VDSPV2;
- bool VDSPV1;
- bool DSPV2;
- bool is3E3R1;
+ bool HardFloat = false;
+ bool HardFloatABI = false;
+ bool FPUV2_SF = false;
+ bool FPUV2_DF = false;
+ bool FPUV3_SF = false;
+ bool FPUV3_DF = false;
+ bool VDSPV2 = false;
+ bool VDSPV1 = false;
+ bool DSPV2 = false;
+ bool is3E3R1 = false;
public:
CSKYTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
@@ -81,6 +86,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
+ bool hasFeature(StringRef Feature) const override;
bool handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) override;
diff --git a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
index fb809956afa80..3a8f927856092 100644
--- a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
@@ -91,6 +91,22 @@ getCSKYFPUFeatures(const Driver &D, const Arg *A, const ArgList &Args,
.Case("fpv3_hsf", llvm::CSKY::FK_FPV3_HSF)
.Case("fpv3_sdf", llvm::CSKY::FK_FPV3_SDF)
.Default(llvm::CSKY::FK_INVALID);
+ if (FPUID == llvm::CSKY::FK_INVALID) {
+ D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
+ return llvm::CSKY::FK_INVALID;
+ }
+
+ auto RemoveTargetFPUFeature =
+ [&Features](ArrayRef<const char *> FPUFeatures) {
+ for (auto FPUFeature : FPUFeatures) {
+ auto it = std::find(Features.begin(), Features.end(), FPUFeature);
+ if (it != Features.end())
+ Features.erase(it);
+ }
+ };
+
+ RemoveTargetFPUFeature({"+fpuv2_sf", "+fpuv2_df", "+fdivdu", "+fpuv3_hi",
+ "+fpuv3_hf", "+fpuv3_sf", "+fpuv3_df"});
if (!llvm::CSKY::getFPUFeatures(FPUID, Features)) {
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
@@ -126,6 +142,8 @@ void csky::getCSKYTargetFeatures(const Driver &D, const llvm::Triple &Triple,
return;
}
cpuName = A->getValue();
+ if (archName.empty())
+ archName = llvm::CSKY::getArchName(Kind);
}
if (archName.empty() && cpuName.empty()) {
@@ -144,11 +162,9 @@ void csky::getCSKYTargetFeatures(const Driver &D, const llvm::Triple &Triple,
Features.push_back("+hard-float");
}
- if (const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ))
- getCSKYFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features);
- else if (FloatABI != csky::FloatABI::Soft && archName.empty())
- llvm::CSKY::getFPUFeatures(llvm::CSKY::FK_AUTO, Features);
-
uint64_t Extension = llvm::CSKY::getDefaultExtensions(cpuName);
llvm::CSKY::getExtensionFeatures(Extension, Features);
+
+ if (const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ))
+ getCSKYFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features);
}
diff --git a/clang/test/Driver/csky-mfpu.c b/clang/test/Driver/csky-mfpu.c
new file mode 100644
index 0000000000000..092ac56de92e4
--- /dev/null
+++ b/clang/test/Driver/csky-mfpu.c
@@ -0,0 +1,93 @@
+// Test that
diff erent values of -mfpu pick correct CSKY FPU target-feature(s).
+
+// RUN: %clang -target csky-unknown-linux %s -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s
+// CHECK-DEFAULT-NOT: "-target-feature" "+hard-float"
+// CHECK-DEFAULT-NOT: "-target-feature" "+hard-float-abi"
+// CHECK-DEFAULT-NOT: "-target-feature" "+fpuv2_sf"
+// CHECK-DEFAULT-NOT: "-target-feature" "+fpuv2_df"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv2 -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV2 %s
+// CHECK-FPV2-NOT: "-target-feature" "+hard-float"
+// CHECK-FPV2-NOT: "-target-feature" "+hard-float-abi"
+// CHECK-FPV2: "-target-feature" "+fpuv2_sf"
+// CHECK-FPV2: "-target-feature" "+fpuv2_df"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv2 -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV2-HARD %s
+// CHECK-FPV2-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV2-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV2-HARD: "-target-feature" "+fpuv2_sf"
+// CHECK-FPV2-HARD: "-target-feature" "+fpuv2_df"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv2_divd -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV2DIVD-HARD %s
+// CHECK-FPV2DIVD-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV2DIVD-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV2DIVD-HARD: "-target-feature" "+fpuv2_sf"
+// CHECK-FPV2DIVD-HARD: "-target-feature" "+fpuv2_df"
+// CHECK-FPV2DIVD-HARD: "-target-feature" "+fdivdu"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=auto -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-AUTO-HARD %s
+// CHECK-AUTO-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-AUTO-HARD: "-target-feature" "+hard-float"
+// CHECK-AUTO-HARD: "-target-feature" "+fpuv2_sf"
+// CHECK-AUTO-HARD: "-target-feature" "+fpuv2_df"
+// CHECK-AUTO-HARD: "-target-feature" "+fdivdu"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv2_sf -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV2SF-HARD %s
+// CHECK-FPV2SF-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV2SF-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV2SF-HARD: "-target-feature" "+fpuv2_sf"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv3 -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV3-HARD %s
+// CHECK-FPV3-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV3-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV3-HARD: "-target-feature" "+fpuv3_hf"
+// CHECK-FPV3-HARD: "-target-feature" "+fpuv3_hi"
+// CHECK-FPV3-HARD: "-target-feature" "+fpuv3_sf"
+// CHECK-FPV3-HARD: "-target-feature" "+fpuv3_df"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv3_hf -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV3HF-HARD %s
+// CHECK-FPV3HF-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV3HF-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV3HF-HARD: "-target-feature" "+fpuv3_hf"
+// CHECK-FPV3HF-HARD: "-target-feature" "+fpuv3_hi"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv3_hsf -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV3HSF-HARD %s
+// CHECK-FPV3HSF-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV3HSF-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV3HSF-HARD: "-target-feature" "+fpuv3_hf"
+// CHECK-FPV3HSF-HARD: "-target-feature" "+fpuv3_hi"
+// CHECK-FPV3HSF-HARD: "-target-feature" "+fpuv3_sf"
+
+// RUN: %clang -target csky-unknown-linux %s -mfpu=fpv3_sdf -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV3DF-HARD %s
+// CHECK-FPV3DF-HARD: "-target-feature" "+hard-float-abi"
+// CHECK-FPV3DF-HARD: "-target-feature" "+hard-float"
+// CHECK-FPV3DF-HARD: "-target-feature" "+fpuv3_sf"
+// CHECK-FPV3DF-HARD: "-target-feature" "+fpuv3_df"
+
+// RUN: %clang -target csky-unknown-linux %s -mcpu=c810 -mfpu=fpv3 -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV3-C810 %s
+// CHECK-FPV3-C810: "-target-feature" "+hard-float-abi"
+// CHECK-FPV3-C810: "-target-feature" "+hard-float"
+// CHECK-FPV3-C810: "-target-feature" "+fpuv3_hf"
+// CHECK-FPV3-C810: "-target-feature" "+fpuv3_hi"
+// CHECK-FPV3-C810: "-target-feature" "+fpuv3_sf"
+// CHECK-FPV3-C810: "-target-feature" "+fpuv3_df"
+// CHECK-FPV3-C810-NOT: "-target-feature" "+fpuv2"
+
+// RUN: %clang -target csky-unknown-linux %s -mcpu=c860 -mfpu=fpv2 -mhard-float -### -o %t.o 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FPV2-C860 %s
+// CHECK-FPV2-C860: "-target-feature" "+hard-float-abi"
+// CHECK-FPV2-C860: "-target-feature" "+hard-float"
+// CHECK-FPV2-C860: "-target-feature" "+fpuv2_sf"
+// CHECK-FPV2-C860: "-target-feature" "+fpuv2_df"
+// CHECK-FPV2-C860-NOT: "-target-feature" "+fpuv3"
\ No newline at end of file
diff --git a/llvm/lib/Support/CSKYTargetParser.cpp b/llvm/lib/Support/CSKYTargetParser.cpp
index 2273b6dce0c75..7e9d2ca0428d7 100644
--- a/llvm/lib/Support/CSKYTargetParser.cpp
+++ b/llvm/lib/Support/CSKYTargetParser.cpp
@@ -43,14 +43,17 @@ bool CSKY::getFPUFeatures(CSKYFPUKind CSKYFPUKind,
break;
case FK_FPV3:
Features.push_back("+fpuv3_hf");
+ Features.push_back("+fpuv3_hi");
Features.push_back("+fpuv3_sf");
Features.push_back("+fpuv3_df");
break;
case FK_FPV3_HF:
Features.push_back("+fpuv3_hf");
+ Features.push_back("+fpuv3_hi");
break;
case FK_FPV3_HSF:
Features.push_back("+fpuv3_hf");
+ Features.push_back("+fpuv3_hi");
Features.push_back("+fpuv3_sf");
break;
case FK_FPV3_SDF:
More information about the llvm-commits
mailing list