From 0fc3c2a547b1eed5ec99650f18040bce860dda5a Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Thu, 24 Aug 2017 16:06:30 +0000 Subject: [PATCH] [mips] Introducing option -mabs=[legacy/2008] 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 | 6 +++++ include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Driver/Options.td | 1 + lib/Basic/Targets/Mips.cpp | 3 +++ lib/Basic/Targets/Mips.h | 12 +++++++--- lib/Driver/ToolChains/Arch/Mips.cpp | 22 +++++++++++++++++ test/Driver/mips-features.c | 25 ++++++++++++++++++++ test/Driver/mips-mabs-warning.c | 6 +++++ test/Preprocessor/init.c | 10 ++++++++ 9 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 test/Driver/mips-mabs-warning.c diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 4f13fa125b..a076b02ea5 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -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; +def warn_target_unsupported_abslegacy : Warning< + "ignoring '-mabs=legacy' option because the '%0' architecture does not support it">, + InGroup; +def warn_target_unsupported_abs2008 : Warning< + "ignoring '-mabs=2008' option because the '%0' architecture does not support it">, + InGroup; def warn_target_unsupported_compact_branches : Warning< "ignoring '-mcompact-branches=' option because the '%0' architecture does not" " support it">, InGroup; diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index dd0ed0b13c..f22910dbae 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -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">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 699c2d5054..6f40bb03e3 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -2066,6 +2066,7 @@ def mno_embedded_data : Flag<["-"], "mno-embedded-data">, Group, HelpText<"Do not place constants in the .rodata section instead of the " ".sdata if they meet the -G threshold (MIPS)">; def mnan_EQ : Joined<["-"], "mnan=">, Group; +def mabs_EQ : Joined<["-"], "mabs=">, Group; def mabicalls : Flag<["-"], "mabicalls">, Group, HelpText<"Enable SVR4-style position-independent code (Mips only)">; def mno_abicalls : Flag<["-"], "mno-abicalls">, Group, diff --git a/lib/Basic/Targets/Mips.cpp b/lib/Basic/Targets/Mips.cpp index 065138b144..3eb39b377b 100644 --- a/lib/Basic/Targets/Mips.cpp +++ b/lib/Basic/Targets/Mips.cpp @@ -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; diff --git a/lib/Basic/Targets/Mips.h b/lib/Basic/Targets/Mips.h index f46aea1e5e..28900f21f8 100644 --- a/lib/Basic/Targets/Mips.h +++ b/lib/Basic/Targets/Mips.h @@ -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; } diff --git a/lib/Driver/ToolChains/Arch/Mips.cpp b/lib/Driver/ToolChains/Arch/Mips.cpp index b96938feb7..70e2e07089 100644 --- a/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/lib/Driver/ToolChains/Arch/Mips.cpp @@ -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, diff --git a/test/Driver/mips-features.c b/test/Driver/mips-features.c index d240253078..5f6833e686 100644 --- a/test/Driver/mips-features.c +++ b/test/Driver/mips-features.c @@ -221,6 +221,31 @@ // 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 index 0000000000..93175be4cc --- /dev/null +++ b/test/Driver/mips-mabs-warning.c @@ -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] diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index 96c11ef09f..bae7c0689b 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -4860,6 +4860,16 @@ // 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 -- 2.40.0