Skip to content

Commit 543913c

Browse files
author
Diogo N. Sampaio
committedMay 9, 2019
[ARM] Fix the extensions implied by a cpu name
Summary: When using `clang -mcpu=CPUNAME+FEATURELIST`, the implied features defined by CPUNAME are not obtained, as the entire string is passed. This fixes that by spiting the cpuname string in the first `+`, if any. For example, when using ```clang -### --target=arm-arm-none-eabi -march=armv7-a -mcpu=cortex-a8+nocrc``` the intrinsic ```"target-feature" "+dsp"``` implied by `cortex-a8` is missing. Reviewers: keith.walker.arm, DavidSpickett, carwil Reviewed By: DavidSpickett Subscribers: javed.absar, kristof.beyls, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61668 llvm-svn: 360324
1 parent 3cdf898 commit 543913c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed
 

‎clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static bool DecodeARMFeatures(const Driver &D, StringRef text,
8888

8989
static void DecodeARMFeaturesFromCPU(const Driver &D, StringRef CPU,
9090
std::vector<StringRef> &Features) {
91+
CPU = CPU.split("+").first;
9192
if (CPU != "generic") {
9293
llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
9394
unsigned Extension = llvm::ARM::getDefaultExtensions(CPU, ArchKind);
@@ -350,11 +351,9 @@ void arm::getARMTargetFeatures(const ToolChain &TC,
350351
D.Diag(clang::diag::warn_drv_unused_argument)
351352
<< CPUArg->getAsString(Args);
352353
CPUName = StringRef(WaCPU->getValue()).substr(6);
353-
checkARMCPUName(D, WaCPU, Args, CPUName, ArchName, Features, Triple);
354-
} else if (CPUArg) {
354+
CPUArg = WaCPU;
355+
} else if (CPUArg)
355356
CPUName = CPUArg->getValue();
356-
checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, Features, Triple);
357-
}
358357

359358
// Add CPU features for generic CPUs
360359
if (CPUName == "native") {
@@ -367,6 +366,8 @@ void arm::getARMTargetFeatures(const ToolChain &TC,
367366
DecodeARMFeaturesFromCPU(D, CPUName, Features);
368367
}
369368

369+
if (CPUArg)
370+
checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, Features, Triple);
370371
// Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=.
371372
const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
372373
if (WaFPU) {

‎clang/test/Driver/arm-cortex-cpus.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -340,30 +340,31 @@
340340
// RUN: %clang -target armv8a-linux-eabi -mcpu=cortex-a53+fp16 -### -c %s 2>&1 | FileCheck --check-prefix CHECK-CORTEX-A53-FP16 %s
341341
// RUN: %clang -target armv8a-linux-eabi -mcpu=cortex-a53+nofp16 -### -c %s 2>&1 | FileCheck --check-prefix CHECK-CORTEX-A53-NOFP16 %s
342342
// CHECK-CORTEX-A53-FP16: "-cc1" {{.*}}"-target-cpu" "cortex-a53" {{.*}}"-target-feature" "+fullfp16"
343-
// CHECK-CORTEX-A53-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
344-
// CHECK-CORTEX-A53-NOFP16: "-cc1" {{.*}}"-target-cpu" "cortex-a53" {{.*}}"-target-feature" "-fullfp16" "-target-feature" "-fp16fml"
343+
// CHECK-CORTEX-A53-FP16-NOT: "-target-feature" "+fp16fml"
344+
// CHECK-CORTEX-A53-NOFP16-NOT: "+fullfp16"
345+
// CHECK-CORTEX-A53-NOFP16-NOT: "+fp16fml"
345346

346347
// RUN: %clang -target armv8a-linux-eabi -march=armv8-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-NOFP16FML %s
347-
// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
348-
// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
348+
// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
349+
// CHECK-V8A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
349350

350351
// RUN: %clang -target armv8a-linux-eabi -march=armv8-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-FP16 %s
351-
// CHECK-V8A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
352+
// CHECK-V8A-FP16-NOT: "-target-feature" "+fp16fml"
352353
// CHECK-V8A-FP16: "-target-feature" "+fullfp16"
353-
// CHECK-V8A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
354+
// CHECK-V8A-FP16-NOT: "-target-feature" "+fp16fml"
354355
// CHECK-V8A-FP16-SAME: {{$}}
355356

356357
// RUN: %clang -target armv8a-linux-eabi -march=armv8-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V8A-FP16FML %s
357358
// CHECK-V8A-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
358359

359360
// RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-NOFP16FML %s
360-
// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
361-
// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
361+
// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
362+
// CHECK-V82A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
362363

363364
// RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-FP16 %s
364-
// CHECK-V82A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
365+
// CHECK-V82A-FP16-NOT: "-target-feature" "+fp16fml"
365366
// CHECK-V82A-FP16: "-target-feature" "+fullfp16"
366-
// CHECK-V82A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
367+
// CHECK-V82A-FP16-NOT: "-target-feature" "+fp16fml"
367368
// CHECK-V82A-FP16-SAME: {{$}}
368369

369370
// RUN: %clang -target armv8a-linux-eabi -march=armv8.2-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V82A-FP16FML %s
@@ -382,13 +383,13 @@
382383
// CHECK-V82A-NOFP16-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
383384

384385
// RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-NOFP16FML %s
385-
// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
386-
// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
386+
// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
387+
// CHECK-V83A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
387388

388389
// RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-FP16 %s
389-
// CHECK-V83A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
390+
// CHECK-V83A-FP16-NOT: "-target-feature" "+fp16fml"
390391
// CHECK-V83A-FP16: "-target-feature" "+fullfp16"
391-
// CHECK-V83A-FP16-NOT: "-target-feature" "{{[+-]}}fp16fml"
392+
// CHECK-V83A-FP16-NOT: "-target-feature" "+fp16fml"
392393
// CHECK-V83A-FP16-SAME: {{$}}
393394

394395
// RUN: %clang -target armv8a-linux-eabi -march=armv8.3-a+fp16fml -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V83A-FP16FML %s
@@ -407,8 +408,8 @@
407408
// CHECK-V83A-NOFP16-FP16FML: "-target-feature" "+fp16fml" "-target-feature" "+fullfp16"
408409

409410
// RUN: %clang -target armv8a-linux-eabi -march=armv8.4-a -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V84A-NOFP16FML %s
410-
// CHECK-V84A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fp16fml"
411-
// CHECK-V84A-NOFP16FML-NOT: "-target-feature" "{{[+-]}}fullfp16"
411+
// CHECK-V84A-NOFP16FML-NOT: "-target-feature" "+fp16fml"
412+
// CHECK-V84A-NOFP16FML-NOT: "-target-feature" "+fullfp16"
412413

413414
// RUN: %clang -target armv8a-linux-eabi -march=armv8.4-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V84A-FP16 %s
414415
// CHECK-V84A-FP16: "-target-feature" "+fullfp16" "-target-feature" "+fp16fml"
@@ -853,3 +854,7 @@
853854
// RUN: %clang -target arm -march=Armv6t2 -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-V6T2-THUMB %s
854855
// RUN: %clang -target arm -march=ARMV6T2 -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-V6T2-THUMB %s
855856
// CHECK-CASE-INSENSITIVE-V6T2-THUMB: "-cc1"{{.*}} "-triple" "thumbv6t2-{{.*}} "-target-cpu" "arm1156t2-s"
857+
858+
// ================== Check that the correct PROCESSOR features are added when used -mcpu=PROCESSOR+FEATURESLIST
859+
// RUN: %clang -### --target=arm-arm-none-eabi -march=armv7-a -mcpu=cortex-a8+nocrc -x c -S -o - - <<< "" 2>&1 | FileCheck -check-prefix=A8FEATURES %s
860+
// A8FEATURES: "-target-feature" "+dsp"

0 commit comments

Comments
 (0)
Please sign in to comment.