koakuma created this revision.
koakuma added reviewers: jrtc27, brad, ro, dcederman.
Herald added subscribers: fedor.sergeev, jyknight.
Herald added a project: All.
koakuma requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

This adds some SPARC feature flags to clang, for those that we have in common 
with GCC:

- `-m[no-]fpu`
- `-m[no-]fsmuld`
- `-m[no-]popc`
- `-m[no-]vis`
- `-m[no-]vis2`
- `-m[no-]vis3`
- `-m[hard/soft]-quad-float`

All have the same meanings as GCC's options 
(https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html).

This fixes, among other things, the -mno-fpu part of bug #40792 
(https://github.com/llvm/llvm-project/issues/40792).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139768

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/test/Driver/sparc-target-features.c

Index: clang/test/Driver/sparc-target-features.c
===================================================================
--- /dev/null
+++ clang/test/Driver/sparc-target-features.c
@@ -0,0 +1,34 @@
+// RUN: %clang --target=sparc -mfpu %s -### 2>&1 | FileCheck -check-prefix=FPU %s
+// RUN: %clang --target=sparc -mno-fpu %s -### 2>&1 | FileCheck -check-prefix=NO-FPU %s
+// FPU: "-mfloat-abi" "hard"
+// NO-FPU: "-mfloat-abi" "soft"
+
+// RUN: %clang --target=sparc -mfsmuld %s -### 2>&1 | FileCheck -check-prefix=FSMULD %s
+// RUN: %clang --target=sparc -mno-fsmuld %s -### 2>&1 | FileCheck -check-prefix=NO-FSMULD %s
+// FSMULD: "-target-feature" "+fsmuld"
+// NO-FSMULD: "-target-feature" "-fsmuld"
+
+// RUN: %clang --target=sparc -mpopc %s -### 2>&1 | FileCheck -check-prefix=POPC %s
+// RUN: %clang --target=sparc -mno-popc %s -### 2>&1 | FileCheck -check-prefix=NO-POPC %s
+// POPC: "-target-feature" "+popc"
+// NO-POPC: "-target-feature" "-popc"
+
+// RUN: %clang --target=sparc -mvis %s -### 2>&1 | FileCheck -check-prefix=VIS %s
+// RUN: %clang --target=sparc -mno-vis %s -### 2>&1 | FileCheck -check-prefix=NO-VIS %s
+// VIS: "-target-feature" "+vis"
+// NO-VIS: "-target-feature" "-vis"
+
+// RUN: %clang --target=sparc -mvis2 %s -### 2>&1 | FileCheck -check-prefix=VIS2 %s
+// RUN: %clang --target=sparc -mno-vis2 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS2 %s
+// VIS2: "-target-feature" "+vis2"
+// NO-VIS2: "-target-feature" "-vis2"
+
+// RUN: %clang --target=sparc -mvis3 %s -### 2>&1 | FileCheck -check-prefix=VIS3 %s
+// RUN: %clang --target=sparc -mno-vis3 %s -### 2>&1 | FileCheck -check-prefix=NO-VIS3 %s
+// VIS3: "-target-feature" "+vis3"
+// NO-VIS3: "-target-feature" "-vis3"
+
+// RUN: %clang --target=sparc -mhard-quad-float %s -### 2>&1 | FileCheck -check-prefix=HARD-QUAD-FLOAT %s
+// RUN: %clang --target=sparc -msoft-quad-float %s -### 2>&1 | FileCheck -check-prefix=SOFT-QUAD-FLOAT %s
+// HARD-QUAD-FLOAT: "-target-feature" "+hard-quad-float"
+// SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -82,12 +82,14 @@
 sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
                                         const ArgList &Args) {
   sparc::FloatABI ABI = sparc::FloatABI::Invalid;
-  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
-                               options::OPT_mhard_float,
+  if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,
+                               options::OPT_mhard_float, options::OPT_mfpu,
                                options::OPT_mfloat_abi_EQ)) {
-    if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
+    if (A->getOption().matches(options::OPT_msoft_float) ||
+        A->getOption().matches(options::OPT_mno_fpu))
       ABI = sparc::FloatABI::Soft;
-    else if (A->getOption().matches(options::OPT_mhard_float))
+    else if (A->getOption().matches(options::OPT_mhard_float) ||
+             A->getOption().matches(options::OPT_mfpu))
       ABI = sparc::FloatABI::Hard;
     else {
       ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
@@ -143,4 +145,47 @@
   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
   if (FloatABI == sparc::FloatABI::Soft)
     Features.push_back("+soft-float");
+
+  if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {
+    if (A->getOption().matches(options::OPT_mfsmuld))
+      Features.push_back("+fsmuld");
+    else
+      Features.push_back("-fsmuld");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {
+    if (A->getOption().matches(options::OPT_mpopc))
+      Features.push_back("+popc");
+    else
+      Features.push_back("-popc");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
+    if (A->getOption().matches(options::OPT_mvis))
+      Features.push_back("+vis");
+    else
+      Features.push_back("-vis");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {
+    if (A->getOption().matches(options::OPT_mvis2))
+      Features.push_back("+vis2");
+    else
+      Features.push_back("-vis2");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {
+    if (A->getOption().matches(options::OPT_mvis3))
+      Features.push_back("+vis3");
+    else
+      Features.push_back("-vis3");
+  }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mhard_quad_float,
+                               options::OPT_msoft_quad_float)) {
+    if (A->getOption().matches(options::OPT_mhard_quad_float))
+      Features.push_back("+hard-quad-float");
+    else
+      Features.push_back("-hard-quad-float");
+  }
 }
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -164,6 +164,8 @@
                            Group<m_Group>, DocName<"ARM">;
 def m_hexagon_Features_Group : OptionGroup<"<hexagon features group>">,
                                Group<m_Group>, DocName<"Hexagon">;
+def m_sparc_Features_Group : OptionGroup<"<sparc features group>">,
+                               Group<m_Group>, DocName<"SPARC">;
 // The features added by this group will not be added to target features.
 // These are explicitly handled.
 def m_hexagon_Features_HVX_Group : OptionGroup<"<hexagon features group>">,
@@ -4525,6 +4527,22 @@
 def mno_nvs : Flag<["-"], "mno-nvs">, Group<m_hexagon_Features_Group>,
   Flags<[CC1Option]>, HelpText<"Disable generation of new-value stores">;
 
+// SPARC feature flags
+def mfpu : Flag<["-"], "mfpu">, Group<m_sparc_Features_Group>;
+def mno_fpu : Flag<["-"], "mno-fpu">, Group<m_sparc_Features_Group>;
+def mfsmuld : Flag<["-"], "mfsmuld">, Group<m_sparc_Features_Group>;
+def mno_fsmuld : Flag<["-"], "mno-fsmuld">, Group<m_sparc_Features_Group>;
+def mpopc : Flag<["-"], "mpopc">, Group<m_sparc_Features_Group>;
+def mno_popc : Flag<["-"], "mno-popc">, Group<m_sparc_Features_Group>;
+def mvis : Flag<["-"], "mvis">, Group<m_sparc_Features_Group>;
+def mno_vis : Flag<["-"], "mno-vis">, Group<m_sparc_Features_Group>;
+def mvis2 : Flag<["-"], "mvis2">, Group<m_sparc_Features_Group>;
+def mno_vis2 : Flag<["-"], "mno-vis2">, Group<m_sparc_Features_Group>;
+def mvis3 : Flag<["-"], "mvis3">, Group<m_sparc_Features_Group>;
+def mno_vis3 : Flag<["-"], "mno-vis3">, Group<m_sparc_Features_Group>;
+def mhard_quad_float : Flag<["-"], "mhard-quad-float">, Group<m_sparc_Features_Group>;
+def msoft_quad_float : Flag<["-"], "msoft-quad-float">, Group<m_sparc_Features_Group>;
+
 // M68k features flags
 def m68000 : Flag<["-"], "m68000">, Group<m_m68k_Features_Group>;
 def m68010 : Flag<["-"], "m68010">, Group<m_m68k_Features_Group>;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to