From 01f6597d21d9cf4fae816f2e90ef45b6b795d70d Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Sun, 6 Sep 2015 16:15:45 +0000 Subject: [PATCH] Refactoring of how ARMTargetInfo handles default target features. Differential Revision: http://reviews.llvm.org/D11299 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246946 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 45 ++++++++++-------------------- test/CodeGen/arm-target-features.c | 27 ++++++++++++++++-- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index ddde0a48f4..b9a74ac8fb 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -4442,37 +4442,20 @@ public: bool initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, std::vector &FeaturesVec) const override { - if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") - Features["vfp2"] = true; - else if (CPU == "cortex-a8" || CPU == "cortex-a9") { - Features["vfp3"] = true; - Features["neon"] = true; - } - else if (CPU == "cortex-a5") { - Features["vfp4"] = true; - Features["neon"] = true; - } else if (CPU == "swift" || CPU == "cortex-a7" || - CPU == "cortex-a12" || CPU == "cortex-a15" || - CPU == "cortex-a17" || CPU == "krait") { - Features["vfp4"] = true; - Features["neon"] = true; - Features["hwdiv"] = true; - Features["hwdiv-arm"] = true; - } else if (CPU == "cyclone" || CPU == "cortex-a53" || CPU == "cortex-a57" || - CPU == "cortex-a72") { - Features["fp-armv8"] = true; - Features["neon"] = true; - Features["hwdiv"] = true; - Features["hwdiv-arm"] = true; - Features["crc"] = true; - Features["crypto"] = true; - } else if (CPU == "cortex-r5" || CPU == "cortex-r7" || ArchVersion == 8) { - Features["hwdiv"] = true; - Features["hwdiv-arm"] = true; - } else if (CPU == "cortex-m3" || CPU == "cortex-m4" || CPU == "cortex-m7" || - CPU == "sc300" || CPU == "cortex-r4" || CPU == "cortex-r4f") { - Features["hwdiv"] = true; - } + + std::vector TargetFeatures; + + // get default FPU features + unsigned FPUKind = llvm::ARM::getDefaultFPU(CPU); + llvm::ARM::getFPUFeatures(FPUKind, TargetFeatures); + + // get default Extension features + unsigned Extensions = llvm::ARM::getDefaultExtensions(CPU); + llvm::ARM::getExtensionFeatures(Extensions, TargetFeatures); + + for (const char *Feature : TargetFeatures) + if (Feature[0] == '+') + Features[Feature+1] = true; if (ArchVersion < 6 || (ArchVersion == 6 && ArchProfile == llvm::ARM::PK_M)) diff --git a/test/CodeGen/arm-target-features.c b/test/CodeGen/arm-target-features.c index 36804b4e3b..9d1c4f203b 100644 --- a/test/CodeGen/arm-target-features.c +++ b/test/CodeGen/arm-target-features.c @@ -1,10 +1,13 @@ // REQUIRES: arm-registered-target // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a8 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3 -// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-a9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3 // CHECK-VFP3: "target-features"="+neon,+vfp3" +// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-a9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-FP16 +// CHECK-VFP3-FP16: "target-features"="+fp16,+neon,+vfp3" + + // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a5 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4 // CHECK-VFP4: "target-features"="+neon,+vfp4" @@ -25,10 +28,30 @@ // CHECK-BASIC-V8: "target-features"="+crc,+crypto,+fp-armv8,+hwdiv,+hwdiv-arm,+neon" +// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5f -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-DIV +// CHECK-VFP3-D16-DIV: "target-features"="+d16,+hwdiv,+hwdiv-arm,+vfp3" + + +// RUN: %clang_cc1 -triple armv7-linux-gnueabi -target-cpu cortex-r4f -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-THUMB-DIV +// CHECK-VFP3-D16-THUMB-DIV: "target-features"="+d16,+hwdiv,+vfp3" + + +// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r7 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-FP16-DIV +// CHECK-VFP3-D16-FP16-DIV: "target-features"="+d16,+fp16,+hwdiv,+hwdiv-arm,+vfp3" + + +// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4f -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-D16-SP-THUMB-DIV +// CHECK-VFP4-D16-SP-THUMB-DIV: "target-features"="+d16,+fp-only-sp,+hwdiv,+vfp4" + + +// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m7 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP5-D16-THUMB-DIV +// CHECK-VFP5-D16-THUMB-DIV: "target-features"="+d16,+fp-armv8,+hwdiv" + + // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-DIV -// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r7 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-DIV // CHECK-DIV: "target-features"="+hwdiv,+hwdiv-arm" + // RUN: %clang_cc1 -triple armv7-linux-gnueabi -target-cpu cortex-r4 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m3 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV -- 2.40.0