Skip to content

Commit 4e50bd3

Browse files
committed
[Clang][ARM] Enable the use of +simd and +nosimd for AArch32 Targets
`+simd` and `+nosimd` are used to emable or disable NEON Instructions when compiling for AArch32 Targets. However, up until now, using these has not been possible. To enable this, these options are mapped to the relevant LLVM backend option (`+neon` and `-neon`) so it can be both enabled and disabled successfully by the user. Tests have been added to ensure this behaviour is maintained in the future, along with updates to existing tests as behaviour has now changed relating to the use of `+simd` and `+nosimd`. As `simd` has been mapped within the ARMTargetParser.def, support for this extension is also added for the `--print-support-extensions` command when the target is AArch32. This will print the `simd` option, along with the description that relates to the Neon feature. This previously was not possible as `simd` did not have a related Feature or Negative Feature.
1 parent d6772d6 commit 4e50bd3

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

clang/test/Driver/print-supported-extensions-arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// CHECK-NEXT: dsp Supports DSP instructions in ARM and/or Thumb2
1313
// CHECK-NEXT: mve Support M-Class Vector Extension with integer ops
1414
// CHECK-NEXT: mve.fp Support M-Class Vector Extension with integer and floating ops
15+
// CHECK-NEXT: simd Enable NEON instructions
1516
// CHECK-NEXT: fp16 Enable half-precision floating point
1617
// CHECK-NEXT: ras Enable Reliability, Availability and Serviceability extensions
1718
// CHECK-NEXT: fp16fml Enable full half-precision floating point fml instructions

clang/test/Preprocessor/arm-target-features.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,3 +1027,11 @@
10271027
// CHECK-R52-NEXT: #define __ARM_VFPV4__ 1
10281028
// CHECK-R52-NOT: #define __ARM_NEON 1
10291029
// CHECK-R52-NOT: #define __ARM_NEON__
1030+
1031+
// Check that on AArch32 appropriate targets, +nosimd correctly disables NEON instructions.
1032+
// RUN: %clang -target arm-none-eabi -march=armv8-a+nosimd -mfloat-abi=hard -x c -E -dM -o - %s | FileCheck -check-prefix=CHECK-NOSIMD %s
1033+
// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52+nosimd -mfloat-abi=hard -x c -E -dM -o - %s | FileCheck -check-prefix=CHECK-NOSIMD %s
1034+
// RUN: %clang -target arm-none-eabi -mcpu=cortex-a57+nosimd -mfloat-abi=hard -x c -E -dM -o - %s | FileCheck -check-prefix=CHECK-NOSIMD %s
1035+
// CHECK-NOSIMD-NOT: #define __ARM_NEON 1
1036+
// CHECK-NOSIMD-NOT: #define __ARM_NEON_FP 0x6
1037+
// CHECK-NOSIMD-NOT: #define __ARM_NEON__ 1

llvm/docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Changes to the AMDGPU Backend
8585

8686
Changes to the ARM Backend
8787
--------------------------
88+
* The `+nosimd` attribute is now fully supported. Previously, this had no effect when being used with
89+
AArch32 targets, however will now disable NEON instructions being generated. The `simd` is also now
90+
printed when the `--print-supported-extensions` option is used..
8891

8992
Changes to the AVR Backend
9093
--------------------------

llvm/include/llvm/TargetParser/ARMTargetParser.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ ARM_ARCH_EXT_NAME("mve.fp", (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP),
229229
"+mve.fp", "-mve.fp")
230230
ARM_ARCH_EXT_NAME("idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB), {}, {})
231231
ARM_ARCH_EXT_NAME("mp", ARM::AEK_MP, {}, {})
232-
ARM_ARCH_EXT_NAME("simd", ARM::AEK_SIMD, {}, {})
232+
ARM_ARCH_EXT_NAME("simd", ARM::AEK_SIMD, "+neon", "-neon")
233233
ARM_ARCH_EXT_NAME("sec", ARM::AEK_SEC, {}, {})
234234
ARM_ARCH_EXT_NAME("virt", ARM::AEK_VIRT, {}, {})
235235
ARM_ARCH_EXT_NAME("fp16", ARM::AEK_FP16, "+fullfp16", "-fullfp16")
@@ -334,8 +334,8 @@ ARM_CPU_NAME("cortex-r7", ARMV7R, FK_VFPV3_D16_FP16, false,
334334
(ARM::AEK_MP | ARM::AEK_HWDIVARM))
335335
ARM_CPU_NAME("cortex-r8", ARMV7R, FK_VFPV3_D16_FP16, false,
336336
(ARM::AEK_MP | ARM::AEK_HWDIVARM))
337-
ARM_CPU_NAME("cortex-r52", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_NONE)
338-
ARM_CPU_NAME("cortex-r52plus", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_NONE)
337+
ARM_CPU_NAME("cortex-r52", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_SIMD)
338+
ARM_CPU_NAME("cortex-r52plus", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_SIMD)
339339
ARM_CPU_NAME("sc300", ARMV7M, FK_NONE, false, ARM::AEK_NONE)
340340
ARM_CPU_NAME("cortex-m3", ARMV7M, FK_NONE, true, ARM::AEK_NONE)
341341
ARM_CPU_NAME("cortex-m4", ARMV7EM, FK_FPV4_SP_D16, true, ARM::AEK_NONE)

llvm/lib/TargetParser/ARMTargetParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ void ARM::PrintSupportedExtensions(StringMap<StringRef> DescMap) {
657657
// Extensions without a feature cannot be used with -march.
658658
if (!Ext.Feature.empty()) {
659659
std::string Description = DescMap[Ext.Name].str();
660+
// With SIMD, this links to the NEON feature, so the description should be
661+
// taken from here, as SIMD does not exist in TableGen.
662+
if (Ext.Name == "simd")
663+
Description = DescMap["neon"].str();
660664
outs() << " "
661665
<< format(Description.empty() ? "%s\n" : "%-20s%s\n",
662666
Ext.Name.str().c_str(), Description.c_str());

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ INSTANTIATE_TEST_SUITE_P(
318318
ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
319319
"7-R"),
320320
ARMCPUTestParams<uint64_t>("cortex-r52", "armv8-r", "neon-fp-armv8",
321-
ARM::AEK_NONE | ARM::AEK_CRC | ARM::AEK_MP |
322-
ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
323-
ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
321+
ARM::AEK_CRC | ARM::AEK_MP | ARM::AEK_VIRT |
322+
ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
323+
ARM::AEK_DSP | ARM::AEK_SIMD,
324324
"8-R"),
325325
ARMCPUTestParams<uint64_t>("cortex-r52plus", "armv8-r", "neon-fp-armv8",
326-
ARM::AEK_NONE | ARM::AEK_CRC | ARM::AEK_MP |
327-
ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
328-
ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
326+
ARM::AEK_CRC | ARM::AEK_MP | ARM::AEK_VIRT |
327+
ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
328+
ARM::AEK_DSP | ARM::AEK_SIMD,
329329
"8-R"),
330330
ARMCPUTestParams<uint64_t>("sc300", "armv7-m", "none",
331331
ARM::AEK_NONE | ARM::AEK_HWDIVTHUMB, "7-M"),
@@ -801,7 +801,7 @@ TEST(TargetParserTest, ARMArchExtFeature) {
801801
{"fp", "nofp", nullptr, nullptr},
802802
{"idiv", "noidiv", nullptr, nullptr},
803803
{"mp", "nomp", nullptr, nullptr},
804-
{"simd", "nosimd", nullptr, nullptr},
804+
{"simd", "nosimd", "+neon", "-neon"},
805805
{"sec", "nosec", nullptr, nullptr},
806806
{"virt", "novirt", nullptr, nullptr},
807807
{"fp16", "nofp16", "+fullfp16", "-fullfp16"},
@@ -1046,7 +1046,6 @@ TEST(TargetParserTest, ARMPrintSupportedExtensions) {
10461046
EXPECT_EQ(std::string::npos, captured.find("invalid"));
10471047
// Should not include anything that lacks a feature name. Checking a few here
10481048
// but not all as if one is hidden correctly the rest should be.
1049-
EXPECT_EQ(std::string::npos, captured.find("simd"));
10501049
EXPECT_EQ(std::string::npos, captured.find("maverick"));
10511050
EXPECT_EQ(std::string::npos, captured.find("xscale"));
10521051
}

0 commit comments

Comments
 (0)