]> granicus.if.org Git - clang/commitdiff
[mips] Introducing option -mabs=[legacy/2008]
authorPetar Jovanovic <petar.jovanovic@imgtec.com>
Thu, 24 Aug 2017 16:06:30 +0000 (16:06 +0000)
committerPetar Jovanovic <petar.jovanovic@imgtec.com>
Thu, 24 Aug 2017 16:06:30 +0000 (16:06 +0000)
In patch r205628 using abs.[ds] instruction is forced, as they should behave
in accordance with flags Has2008 and ABS2008. Unfortunately for revisions
prior mips32r6 and mips64r6, abs.[ds] is not generating correct result when
working with NaNs. To generate a sequence which always produce a correct
result but also to allow user more control on how his code is compiled,
option -mabs is added where user can choose legacy or 2008.
By default legacy mode is used on revisions prior R6. Mips32r6 and mips64r6
use abs2008 mode by default.

Patch by Aleksandar Beserminji

Differential Revision: https://reviews.llvm.org/D35982

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311669 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticDriverKinds.td
include/clang/Basic/DiagnosticGroups.td
include/clang/Driver/Options.td
lib/Basic/Targets/Mips.cpp
lib/Basic/Targets/Mips.h
lib/Driver/ToolChains/Arch/Mips.cpp
test/Driver/mips-features.c
test/Driver/mips-mabs-warning.c [new file with mode: 0644]
test/Preprocessor/init.c

index 4f13fa125b2ae84ff8a0fa688c1a4cb66b4ac41f..a076b02ea53381b56fa597eeb309e9a1cff7f37a 100644 (file)
@@ -285,6 +285,12 @@ def warn_target_unsupported_nan2008 : Warning<
 def warn_target_unsupported_nanlegacy : Warning<
   "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">,
   InGroup<UnsupportedNan>;
+def warn_target_unsupported_abslegacy : Warning<
+  "ignoring '-mabs=legacy' option because the '%0' architecture does not support it">,
+  InGroup<UnsupportedAbs>;
+def warn_target_unsupported_abs2008 : Warning<
+  "ignoring '-mabs=2008' option because the '%0' architecture does not support it">,
+  InGroup<UnsupportedAbs>;
 def warn_target_unsupported_compact_branches : Warning<
   "ignoring '-mcompact-branches=' option because the '%0' architecture does not"
   " support it">, InGroup<UnsupportedCB>;
index dd0ed0b13cc4e900e6fc062d24f18d8792459285..f22910dbaea2a028a37e0686482275e94e10f921 100644 (file)
@@ -61,6 +61,7 @@ def FloatConversion :
 def DoublePromotion : DiagGroup<"double-promotion">;
 def EnumTooLarge : DiagGroup<"enum-too-large">;
 def UnsupportedNan : DiagGroup<"unsupported-nan">;
+def UnsupportedAbs : DiagGroup<"unsupported-abs">;
 def UnsupportedCB : DiagGroup<"unsupported-cb">;
 def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
 def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
index 699c2d5054bc4a381d95ce956e033c5b1b8a39ff..6f40bb03e35ecf380dff41b536fb2092fbc6ebd6 100644 (file)
@@ -2066,6 +2066,7 @@ def mno_embedded_data : Flag<["-"], "mno-embedded-data">, Group<m_Group>,
   HelpText<"Do not place constants in the .rodata section instead of the "
            ".sdata if they meet the -G <size> threshold (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group<m_Group>;
+def mabs_EQ : Joined<["-"], "mabs=">, Group<m_Group>;
 def mabicalls : Flag<["-"], "mabicalls">, Group<m_Group>,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;
 def mno_abicalls : Flag<["-"], "mno-abicalls">, Group<m_Group>,
index 065138b14486dec2fc5f9fa53c7591bdecd98be4..3eb39b377be1c167dd7126e2c6a831c689f1321b 100644 (file)
@@ -149,6 +149,9 @@ void MipsTargetInfo::getTargetDefines(const LangOptions &Opts,
   if (IsNan2008)
     Builder.defineMacro("__mips_nan2008", Twine(1));
 
+  if (IsAbs2008)
+    Builder.defineMacro("__mips_abs2008", Twine(1));
+
   switch (DspRev) {
   default:
     break;
index f46aea1e5e7c6d4ba151ba17901a547673c146c6..28900f21f86baa6d759458a2b8e00e07d6e4fc0c 100644 (file)
@@ -46,6 +46,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
   bool IsMips16;
   bool IsMicromips;
   bool IsNan2008;
+  bool IsAbs2008;
   bool IsSingleFloat;
   bool IsNoABICalls;
   bool CanUseBSDABICalls;
@@ -61,9 +62,9 @@ protected:
 public:
   MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
       : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
-        IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
-        CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
-        HasMSA(false), DisableMadd4(false), HasFP64(false) {
+        IsNan2008(false), IsAbs2008(false), IsSingleFloat(false),
+        IsNoABICalls(false), CanUseBSDABICalls(false), FloatABI(HardFloat),
+        DspRev(NoDSP), HasMSA(false), DisableMadd4(false), HasFP64(false) {
     TheCXXABI.set(TargetCXXABI::GenericMIPS);
 
     setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -300,6 +301,7 @@ public:
     IsMips16 = false;
     IsMicromips = false;
     IsNan2008 = isIEEE754_2008Default();
+    IsAbs2008 = isIEEE754_2008Default();
     IsSingleFloat = false;
     FloatABI = HardFloat;
     DspRev = NoDSP;
@@ -330,6 +332,10 @@ public:
         IsNan2008 = true;
       else if (Feature == "-nan2008")
         IsNan2008 = false;
+      else if (Feature == "+abs2008")
+        IsAbs2008 = true;
+      else if (Feature == "-abs2008")
+        IsAbs2008 = false;
       else if (Feature == "+noabicalls")
         IsNoABICalls = true;
     }
index b96938feb78eaeecdee870167949e221786357ad..70e2e07089383091be1a549b628a17ba23dc67fa 100644 (file)
@@ -283,6 +283,28 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
           << A->getOption().getName() << Val;
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mabs_EQ)) {
+    StringRef Val = StringRef(A->getValue());
+    if (Val == "2008") {
+      if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
+        Features.push_back("+abs2008");
+      } else {
+        Features.push_back("-abs2008");
+        D.Diag(diag::warn_target_unsupported_abs2008) << CPUName;
+      }
+    } else if (Val == "legacy") {
+      if (mips::getIEEE754Standard(CPUName) & mips::Legacy) {
+        Features.push_back("-abs2008");
+      } else {
+        Features.push_back("+abs2008");
+        D.Diag(diag::warn_target_unsupported_abslegacy) << CPUName;
+      }
+    } else {
+      D.Diag(diag::err_drv_unsupported_option_argument)
+          << A->getOption().getName() << Val;
+    }
+  }
+
   AddTargetFeature(Args, Features, options::OPT_msingle_float,
                    options::OPT_mdouble_float, "single-float");
   AddTargetFeature(Args, Features, options::OPT_mips16, options::OPT_mno_mips16,
index d240253078e51adbb43ce7c1b2c8eca0bbdf6355..5f6833e686fdcb96749e8968534b6b4857c429f1 100644 (file)
 // RUN:   | FileCheck --check-prefix=CHECK-NANLEGACY %s
 // CHECK-NANLEGACY: "-target-feature" "-nan2008"
 //
+// -mabs=2008 on pre R2
+// RUN: %clang -target mips-linux-gnu -march=mips32 -### -c %s \
+// RUN:     -mabs=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACY %s
+//
+// -mabs=2008
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN:     -mabs=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABS2008 %s
+//
+// -mabs=legacy
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN:     -mabs=legacy 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACY %s
+//
+// -mabs=legacy on R6
+// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \
+// RUN:     -mabs=legacy 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABS2008 %s
+//
+// CHECK-ABSLEGACY: "-target-feature" "-abs2008"
+// CHECK-ABSLEGACY-NOT: "-target-feature" "+abs2008"
+// CHECK-ABS2008: "-target-feature" "+abs2008"
+// CHECK-ABS2008-NOT: "-target-feature" "-abs2008"
+//
 // -mcompact-branches=never
 // RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \
 // RUN:     -mcompact-branches=never 2>&1 \
diff --git a/test/Driver/mips-mabs-warning.c b/test/Driver/mips-mabs-warning.c
new file mode 100644 (file)
index 0000000..93175be
--- /dev/null
@@ -0,0 +1,6 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang -c -target mips-unknown-gnu -mcpu=mips32 -mabs=2008 %s 2>&1 | FileCheck -check-prefix=NO2008 %s
+// NO2008: warning: ignoring '-mabs=2008' option because the 'mips32' architecture does not support it [-Wunsupported-abs]
+
+// RUN: %clang -c -target mips-unknown-gnu -mcpu=mips32r6 -mabs=legacy %s 2>&1 | FileCheck -check-prefix=NOLEGACY %s
+// NOLEGACY: warning: ignoring '-mabs=legacy' option because the 'mips32r6' architecture does not support it [-Wunsupported-abs]
index 96c11ef09ff80bd7a7f2c6b0e3c6363f48c081ef..bae7c0689babdf07a779bb4fbae82bc4b55348e1 100644 (file)
 // RUN:   | FileCheck -match-full-lines -check-prefix NOMIPS-NAN2008 %s
 // NOMIPS-NAN2008-NOT:#define __mips_nan2008 1
 //
+// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +abs2008 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-ABS2008 %s
+// MIPS-ABS2008:#define __mips_abs2008 1
+//
+// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature -abs2008 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix NOMIPS-ABS2008 %s
+// NOMIPS-ABS2008-NOT:#define __mips_abs2008 1
+//
 // RUN: %clang_cc1 -target-feature -fp64 \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP32 %s