[PATCH] D82948: [Driver][ARM] Disable unsupported features when nofp arch extension is used

Victor Campos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 1 04:49:37 PDT 2020


vhscampos created this revision.
Herald added subscribers: cfe-commits, danielkiss, kristof.beyls.
Herald added a project: clang.
vhscampos added a child revision: D82949: [Driver][ARM] Disable bf16 when hardware FP support is missing.
vhscampos added a reviewer: chill.

A list of target features is disabled when there is no hardware
floating-point support. This is the case when one of the following
options is passed to clang:

- -mfloat-abi=soft
- -mfpu=none

This option list is missing, however, the extension "+nofp" that can be
specified in -march flags, such as "-march=armv8-a+nofp".

This patch also disables unsupported target features when nofp is passed
to -march.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82948

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp


Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -285,6 +285,35 @@
          (NoMVE == F.rend() || std::distance(MVE, NoMVE) > 0);
 }
 
+static void appendNoFPUnsupportedFeatures(const arm::FloatABI ABI,
+                                          const unsigned FPUID,
+                                          const StringRef &ArchName,
+                                          std::vector<StringRef> &Features) {
+  auto checkFPDisabledInArchName = [](const StringRef &ArchName) {
+    SmallVector<StringRef, 8> Split;
+    ArchName.split(Split, '+', -1, false);
+    return llvm::any_of(
+        Split, [](const StringRef &Extension) { return Extension == "nofp"; });
+  };
+
+  if (ABI == arm::FloatABI::Soft) {
+    llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features);
+
+    // Disable all features relating to hardware FP, not already disabled by the
+    // above call.
+    Features.insert(Features.end(),
+                    {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"});
+  } else if (FPUID == llvm::ARM::FK_NONE ||
+             checkFPDisabledInArchName(ArchName)) {
+    // -mfpu=none or -march=armvX+nofp is *very* similar to -mfloat-abi=soft,
+    // only that it should not disable MVE-I.
+    Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"});
+    if (!hasIntegerMVE(Features)) {
+      Features.emplace_back("-fpregs");
+    }
+  }
+}
+
 void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
                                const ArgList &Args, ArgStringList &CmdArgs,
                                std::vector<StringRef> &Features, bool ForAS) {
@@ -455,23 +484,10 @@
       Features.push_back("+fullfp16");
   }
 
-  // Setting -msoft-float/-mfloat-abi=soft effectively disables the FPU (GCC
-  // ignores the -mfpu options in this case).
-  // Note that the ABI can also be set implicitly by the target selected.
-  if (ABI == arm::FloatABI::Soft) {
-    llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features);
-
-    // Disable all features relating to hardware FP, not already disabled by the
-    // above call.
-    Features.insert(Features.end(),
-                    {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"});
-  } else if (FPUID == llvm::ARM::FK_NONE) {
-    // -mfpu=none is *very* similar to -mfloat-abi=soft, only that it should not
-    // disable MVE-I.
-    Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"});
-    if (!hasIntegerMVE(Features))
-      Features.emplace_back("-fpregs");
-  }
+  // Setting -msoft-float/-mfloat-abi=soft, -mfpu=none, or adding +nofp to
+  // -march effectively disables the FPU (GCC ignores the -mfpu options in this
+  // case). Note that the ABI can also be set implicitly by the target selected.
+  appendNoFPUnsupportedFeatures(ABI, FPUID, ArchName, Features);
 
   // En/disable crc code generation.
   if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82948.274757.patch
Type: text/x-patch
Size: 3102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200701/0aa52785/attachment.bin>


More information about the cfe-commits mailing list