Skip to content

Commit 5076511

Browse files
committedAug 24, 2017
[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 llvm-svn: 311669
1 parent 2d1f6d6 commit 5076511

File tree

9 files changed

+83
-3
lines changed

9 files changed

+83
-3
lines changed
 

‎clang/include/clang/Basic/DiagnosticDriverKinds.td

+6
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ def warn_target_unsupported_nan2008 : Warning<
285285
def warn_target_unsupported_nanlegacy : Warning<
286286
"ignoring '-mnan=legacy' option because the '%0' architecture does not support it">,
287287
InGroup<UnsupportedNan>;
288+
def warn_target_unsupported_abslegacy : Warning<
289+
"ignoring '-mabs=legacy' option because the '%0' architecture does not support it">,
290+
InGroup<UnsupportedAbs>;
291+
def warn_target_unsupported_abs2008 : Warning<
292+
"ignoring '-mabs=2008' option because the '%0' architecture does not support it">,
293+
InGroup<UnsupportedAbs>;
288294
def warn_target_unsupported_compact_branches : Warning<
289295
"ignoring '-mcompact-branches=' option because the '%0' architecture does not"
290296
" support it">, InGroup<UnsupportedCB>;

‎clang/include/clang/Basic/DiagnosticGroups.td

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def FloatConversion :
6161
def DoublePromotion : DiagGroup<"double-promotion">;
6262
def EnumTooLarge : DiagGroup<"enum-too-large">;
6363
def UnsupportedNan : DiagGroup<"unsupported-nan">;
64+
def UnsupportedAbs : DiagGroup<"unsupported-abs">;
6465
def UnsupportedCB : DiagGroup<"unsupported-cb">;
6566
def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
6667
def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;

‎clang/include/clang/Driver/Options.td

+1
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,7 @@ def mno_embedded_data : Flag<["-"], "mno-embedded-data">, Group<m_Group>,
20662066
HelpText<"Do not place constants in the .rodata section instead of the "
20672067
".sdata if they meet the -G <size> threshold (MIPS)">;
20682068
def mnan_EQ : Joined<["-"], "mnan=">, Group<m_Group>;
2069+
def mabs_EQ : Joined<["-"], "mabs=">, Group<m_Group>;
20692070
def mabicalls : Flag<["-"], "mabicalls">, Group<m_Group>,
20702071
HelpText<"Enable SVR4-style position-independent code (Mips only)">;
20712072
def mno_abicalls : Flag<["-"], "mno-abicalls">, Group<m_Group>,

‎clang/lib/Basic/Targets/Mips.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ void MipsTargetInfo::getTargetDefines(const LangOptions &Opts,
149149
if (IsNan2008)
150150
Builder.defineMacro("__mips_nan2008", Twine(1));
151151

152+
if (IsAbs2008)
153+
Builder.defineMacro("__mips_abs2008", Twine(1));
154+
152155
switch (DspRev) {
153156
default:
154157
break;

‎clang/lib/Basic/Targets/Mips.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
4646
bool IsMips16;
4747
bool IsMicromips;
4848
bool IsNan2008;
49+
bool IsAbs2008;
4950
bool IsSingleFloat;
5051
bool IsNoABICalls;
5152
bool CanUseBSDABICalls;
@@ -61,9 +62,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
6162
public:
6263
MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
6364
: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
64-
IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
65-
CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
66-
HasMSA(false), DisableMadd4(false), HasFP64(false) {
65+
IsNan2008(false), IsAbs2008(false), IsSingleFloat(false),
66+
IsNoABICalls(false), CanUseBSDABICalls(false), FloatABI(HardFloat),
67+
DspRev(NoDSP), HasMSA(false), DisableMadd4(false), HasFP64(false) {
6768
TheCXXABI.set(TargetCXXABI::GenericMIPS);
6869

6970
setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -300,6 +301,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
300301
IsMips16 = false;
301302
IsMicromips = false;
302303
IsNan2008 = isIEEE754_2008Default();
304+
IsAbs2008 = isIEEE754_2008Default();
303305
IsSingleFloat = false;
304306
FloatABI = HardFloat;
305307
DspRev = NoDSP;
@@ -330,6 +332,10 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
330332
IsNan2008 = true;
331333
else if (Feature == "-nan2008")
332334
IsNan2008 = false;
335+
else if (Feature == "+abs2008")
336+
IsAbs2008 = true;
337+
else if (Feature == "-abs2008")
338+
IsAbs2008 = false;
333339
else if (Feature == "+noabicalls")
334340
IsNoABICalls = true;
335341
}

‎clang/lib/Driver/ToolChains/Arch/Mips.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,28 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
283283
<< A->getOption().getName() << Val;
284284
}
285285

286+
if (Arg *A = Args.getLastArg(options::OPT_mabs_EQ)) {
287+
StringRef Val = StringRef(A->getValue());
288+
if (Val == "2008") {
289+
if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
290+
Features.push_back("+abs2008");
291+
} else {
292+
Features.push_back("-abs2008");
293+
D.Diag(diag::warn_target_unsupported_abs2008) << CPUName;
294+
}
295+
} else if (Val == "legacy") {
296+
if (mips::getIEEE754Standard(CPUName) & mips::Legacy) {
297+
Features.push_back("-abs2008");
298+
} else {
299+
Features.push_back("+abs2008");
300+
D.Diag(diag::warn_target_unsupported_abslegacy) << CPUName;
301+
}
302+
} else {
303+
D.Diag(diag::err_drv_unsupported_option_argument)
304+
<< A->getOption().getName() << Val;
305+
}
306+
}
307+
286308
AddTargetFeature(Args, Features, options::OPT_msingle_float,
287309
options::OPT_mdouble_float, "single-float");
288310
AddTargetFeature(Args, Features, options::OPT_mips16, options::OPT_mno_mips16,

‎clang/test/Driver/mips-features.c

+25
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,31 @@
221221
// RUN: | FileCheck --check-prefix=CHECK-NANLEGACY %s
222222
// CHECK-NANLEGACY: "-target-feature" "-nan2008"
223223
//
224+
// -mabs=2008 on pre R2
225+
// RUN: %clang -target mips-linux-gnu -march=mips32 -### -c %s \
226+
// RUN: -mabs=2008 2>&1 \
227+
// RUN: | FileCheck --check-prefix=CHECK-ABSLEGACY %s
228+
//
229+
// -mabs=2008
230+
// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
231+
// RUN: -mabs=2008 2>&1 \
232+
// RUN: | FileCheck --check-prefix=CHECK-ABS2008 %s
233+
//
234+
// -mabs=legacy
235+
// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
236+
// RUN: -mabs=legacy 2>&1 \
237+
// RUN: | FileCheck --check-prefix=CHECK-ABSLEGACY %s
238+
//
239+
// -mabs=legacy on R6
240+
// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \
241+
// RUN: -mabs=legacy 2>&1 \
242+
// RUN: | FileCheck --check-prefix=CHECK-ABS2008 %s
243+
//
244+
// CHECK-ABSLEGACY: "-target-feature" "-abs2008"
245+
// CHECK-ABSLEGACY-NOT: "-target-feature" "+abs2008"
246+
// CHECK-ABS2008: "-target-feature" "+abs2008"
247+
// CHECK-ABS2008-NOT: "-target-feature" "-abs2008"
248+
//
224249
// -mcompact-branches=never
225250
// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \
226251
// RUN: -mcompact-branches=never 2>&1 \

‎clang/test/Driver/mips-mabs-warning.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// REQUIRES: mips-registered-target
2+
// RUN: %clang -c -target mips-unknown-gnu -mcpu=mips32 -mabs=2008 %s 2>&1 | FileCheck -check-prefix=NO2008 %s
3+
// NO2008: warning: ignoring '-mabs=2008' option because the 'mips32' architecture does not support it [-Wunsupported-abs]
4+
5+
// RUN: %clang -c -target mips-unknown-gnu -mcpu=mips32r6 -mabs=legacy %s 2>&1 | FileCheck -check-prefix=NOLEGACY %s
6+
// NOLEGACY: warning: ignoring '-mabs=legacy' option because the 'mips32r6' architecture does not support it [-Wunsupported-abs]

‎clang/test/Preprocessor/init.c

+10
Original file line numberDiff line numberDiff line change
@@ -4860,6 +4860,16 @@
48604860
// RUN: | FileCheck -match-full-lines -check-prefix NOMIPS-NAN2008 %s
48614861
// NOMIPS-NAN2008-NOT:#define __mips_nan2008 1
48624862
//
4863+
// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +abs2008 \
4864+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
4865+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ABS2008 %s
4866+
// MIPS-ABS2008:#define __mips_abs2008 1
4867+
//
4868+
// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature -abs2008 \
4869+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
4870+
// RUN: | FileCheck -match-full-lines -check-prefix NOMIPS-ABS2008 %s
4871+
// NOMIPS-ABS2008-NOT:#define __mips_abs2008 1
4872+
//
48634873
// RUN: %clang_cc1 -target-feature -fp64 \
48644874
// RUN: -E -dM -triple=mips-none-none < /dev/null \
48654875
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-MFP32 %s

0 commit comments

Comments
 (0)
Please sign in to comment.