[clang] 3627c91 - [ARM][TargetParser] Improve handling of dependencies between target features
Momchil Velikov via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 5 08:08:07 PST 2020
Author: Momchil Velikov
Date: 2020-02-05T16:07:51Z
New Revision: 3627c91ead934486fdb3986b911482a78f101309
URL: https://github.com/llvm/llvm-project/commit/3627c91ead934486fdb3986b911482a78f101309
DIFF: https://github.com/llvm/llvm-project/commit/3627c91ead934486fdb3986b911482a78f101309.diff
LOG: [ARM][TargetParser] Improve handling of dependencies between target features
The patch at https://reviews.llvm.org/D64048 added "negative"
dependency handling in `ARM::appendArchExtFeatures`: feature "noX"
removes all features, which imply "X".
This patch adds the "positive" handling: feature "X" adds all the
feature strings implied by "X".
(This patch also comes from the suggestion here
https://reviews.llvm.org/D72633#inline-658582)
Differential Revision: https://reviews.llvm.org/D72762
Added:
Modified:
clang/lib/Basic/Targets/ARM.cpp
clang/test/Driver/arm-mfpu.c
clang/test/Preprocessor/arm-target-features.c
llvm/lib/Support/ARMTargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c6f661fdec99..02144c6ebe85 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -480,10 +480,8 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
} else if (Feature == "+dotprod") {
DotProd = true;
} else if (Feature == "+mve") {
- DSP = 1;
MVE |= MVE_INT;
} else if (Feature == "+mve.fp") {
- DSP = 1;
HasLegalHalfType = true;
FPU |= FPARMV8;
MVE |= MVE_INT | MVE_FP;
diff --git a/clang/test/Driver/arm-mfpu.c b/clang/test/Driver/arm-mfpu.c
index c3731fa5bd63..5309977d0f90 100644
--- a/clang/test/Driver/arm-mfpu.c
+++ b/clang/test/Driver/arm-mfpu.c
@@ -414,12 +414,14 @@
// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "-d32"
// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "-neon"
// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "-crypto"
+// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "+mve"
+// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "+dsp"
// CHECK-MVEFP-FPUNONE-DAG: "-target-feature" "-mve.fp"
// CHECK-MVEFP-FPUNONE-NOT: "-target-feature" "-fpregs"
-
// RUN: %clang -target arm-none-none-eabi %s -march=armv8.1-m.main+mve -mfpu=none -### -c 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MVEI-FPUNONE %s
// CHECK-MVEI-FPUNONE-DAG: "-target-feature" "-mve.fp"
// CHECK-MVEI-FPUNONE-DAG: "-target-feature" "+mve"
+// CHECK-MVEI-FPUNONE-DAG: "-target-feature" "+dsp"
// CHECK-MVEI-FPUNONE-NOT: "-target-feature" "-fpregs"
diff --git a/clang/test/Preprocessor/arm-target-features.c b/clang/test/Preprocessor/arm-target-features.c
index 3d80a1bd88cf..72b77b6124fe 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -761,9 +761,10 @@
// CHECK-V81M-MVEFP: #define __ARM_FEATURE_SIMD32 1
// CHECK-V81M-MVEFP: #define __ARM_FPV5__ 1
-// nofp discards mve.fp
+// nofp discards mve.fp, but not mve/dsp
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nofp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOFP %s
-// CHECK-V81M-MVEFP-NOFP-NOT: #define __ARM_FEATURE_MVE
+// CHECK-V81M-MVEFP-NOFP: #define __ARM_FEATURE_DSP 1
+// CHECK-V81M-MVEFP-NOFP: #define __ARM_FEATURE_MVE 1
// nomve discards mve.fp
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nomve -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOMVE %s
@@ -773,11 +774,16 @@
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s
// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 1
-// nodsp discards both dsp and mve
+// nodsp discards both dsp and mve ...
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+nodsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-NODSP %s
// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE
// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP
+// ... and also mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nodsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-NODSP %s
+// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE
+// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP
+
// RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81A %s
// CHECK-V81A: #define __ARM_ARCH 8
// CHECK-V81A: #define __ARM_ARCH_8_1A__ 1
diff --git a/llvm/lib/Support/ARMTargetParser.cpp b/llvm/lib/Support/ARMTargetParser.cpp
index 360e64a5a5f4..3c3c2103a5c1 100644
--- a/llvm/lib/Support/ARMTargetParser.cpp
+++ b/llvm/lib/Support/ARMTargetParser.cpp
@@ -498,10 +498,13 @@ bool ARM::appendArchExtFeatures(
return false;
for (const auto AE : ARCHExtNames) {
- if (Negated && (AE.ID & ID) == ID && AE.NegFeature)
- Features.push_back(AE.NegFeature);
- else if (AE.ID == ID && AE.Feature)
- Features.push_back(AE.Feature);
+ if (Negated) {
+ if ((AE.ID & ID) == ID && AE.NegFeature)
+ Features.push_back(AE.NegFeature);
+ } else {
+ if ((AE.ID & ID) == AE.ID && AE.Feature)
+ Features.push_back(AE.Feature);
+ }
}
if (CPU == "")
diff --git a/llvm/unittests/Support/TargetParserTest.cpp b/llvm/unittests/Support/TargetParserTest.cpp
index dbdaedd3892d..9349f7670146 100644
--- a/llvm/unittests/Support/TargetParserTest.cpp
+++ b/llvm/unittests/Support/TargetParserTest.cpp
@@ -637,6 +637,27 @@ TEST(TargetParserTest, ARMArchExtFeature) {
}
}
+static bool
+testArchExtDependency(const char *ArchExt,
+ const std::initializer_list<const char *> &Expected) {
+ std::vector<StringRef> Features;
+
+ if (!ARM::appendArchExtFeatures("", ARM::ArchKind::ARMV8_1MMainline, ArchExt,
+ Features))
+ return false;
+
+ return llvm::all_of(Expected, [&](StringRef Ext) {
+ return llvm::is_contained(Features, Ext);
+ });
+}
+
+TEST(TargetParserTest, ARMArchExtDependencies) {
+ EXPECT_TRUE(testArchExtDependency("mve", {"+mve", "+dsp"}));
+ EXPECT_TRUE(testArchExtDependency("mve.fp", {"+mve.fp", "+mve", "+dsp"}));
+ EXPECT_TRUE(testArchExtDependency("nodsp", {"-dsp", "-mve", "-mve.fp"}));
+ EXPECT_TRUE(testArchExtDependency("nomve", {"-mve", "-mve.fp"}));
+}
+
TEST(TargetParserTest, ARMparseHWDiv) {
const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
More information about the cfe-commits
mailing list