Skip to content

Commit c2f02e3

Browse files
committed
Clang: Define macro _MIPS_SPFPSET
GCC defines this macro for how many single-precision floating point registers can be used. If the -mno-odd-spreg option is given, it will be 16; if either -mno-odd-spreg nor -modd-spreg are given, we set it to 16 for FPXX. Reviewed By: theraven Differential Revision: https://reviews.llvm.org/D157896
1 parent 9322216 commit c2f02e3

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

clang/lib/Basic/Targets/Mips.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ void MipsTargetInfo::getTargetDefines(const LangOptions &Opts,
149149
Builder.defineMacro("_MIPS_FPSET", Twine(32));
150150
else
151151
Builder.defineMacro("_MIPS_FPSET", Twine(16));
152+
if (NoOddSpreg)
153+
Builder.defineMacro("_MIPS_SPFPSET", Twine(16));
154+
else
155+
Builder.defineMacro("_MIPS_SPFPSET", Twine(32));
152156

153157
if (IsMips16)
154158
Builder.defineMacro("__mips16", Twine(1));

clang/lib/Basic/Targets/Mips.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
5353
bool HasMSA;
5454
bool DisableMadd4;
5555
bool UseIndirectJumpHazard;
56+
bool NoOddSpreg;
5657

5758
protected:
5859
enum FPModeEnum { FPXX, FP32, FP64 } FPMode;
@@ -313,6 +314,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
313314
FloatABI = HardFloat;
314315
DspRev = NoDSP;
315316
FPMode = isFP64Default() ? FP64 : FPXX;
317+
NoOddSpreg = false;
318+
bool OddSpregGiven = false;
316319

317320
for (const auto &Feature : Features) {
318321
if (Feature == "+single-float")
@@ -349,8 +352,18 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
349352
IsNoABICalls = true;
350353
else if (Feature == "+use-indirect-jump-hazard")
351354
UseIndirectJumpHazard = true;
355+
else if (Feature == "+nooddspreg") {
356+
NoOddSpreg = true;
357+
OddSpregGiven = false;
358+
} else if (Feature == "-nooddspreg") {
359+
NoOddSpreg = false;
360+
OddSpregGiven = true;
361+
}
352362
}
353363

364+
if (FPMode == FPXX && !OddSpregGiven)
365+
NoOddSpreg = true;
366+
354367
setDataLayout();
355368

356369
return true;

clang/test/Preprocessor/init-mips.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// MIPS32BE:#define _MIPS_ARCH_MIPS32R2 1
1111
// MIPS32BE:#define _MIPS_FPSET 16
1212
// MIPS32BE:#define _MIPS_SIM _ABIO32
13+
// MIPS32BE:#define _MIPS_SPFPSET 16
1314
// MIPS32BE:#define _MIPS_SZINT 32
1415
// MIPS32BE:#define _MIPS_SZLONG 32
1516
// MIPS32BE:#define _MIPS_SZPTR 32
@@ -220,6 +221,7 @@
220221
// MIPS32EL:#define _MIPS_ARCH_MIPS32R2 1
221222
// MIPS32EL:#define _MIPS_FPSET 16
222223
// MIPS32EL:#define _MIPS_SIM _ABIO32
224+
// MIPS32EL:#define _MIPS_SPFPSET 16
223225
// MIPS32EL:#define _MIPS_SZINT 32
224226
// MIPS32EL:#define _MIPS_SZLONG 32
225227
// MIPS32EL:#define _MIPS_SZPTR 32
@@ -432,6 +434,7 @@
432434
// MIPSN32BE: #define _MIPS_FPSET 32
433435
// MIPSN32BE: #define _MIPS_ISA _MIPS_ISA_MIPS64
434436
// MIPSN32BE: #define _MIPS_SIM _ABIN32
437+
// MIPSN32BE: #define _MIPS_SPFPSET 32
435438
// MIPSN32BE: #define _MIPS_SZINT 32
436439
// MIPSN32BE: #define _MIPS_SZLONG 32
437440
// MIPSN32BE: #define _MIPS_SZPTR 32
@@ -739,6 +742,7 @@
739742
// MIPSN32EL: #define _MIPS_FPSET 32
740743
// MIPSN32EL: #define _MIPS_ISA _MIPS_ISA_MIPS64
741744
// MIPSN32EL: #define _MIPS_SIM _ABIN32
745+
// MIPSN32EL: #define _MIPS_SPFPSET 32
742746
// MIPSN32EL: #define _MIPS_SZINT 32
743747
// MIPSN32EL: #define _MIPS_SZLONG 32
744748
// MIPSN32EL: #define _MIPS_SZPTR 32
@@ -1043,6 +1047,7 @@
10431047
// MIPS64BE:#define _MIPS_ARCH_MIPS64R2 1
10441048
// MIPS64BE:#define _MIPS_FPSET 32
10451049
// MIPS64BE:#define _MIPS_SIM _ABI64
1050+
// MIPS64BE:#define _MIPS_SPFPSET 32
10461051
// MIPS64BE:#define _MIPS_SZINT 32
10471052
// MIPS64BE:#define _MIPS_SZLONG 64
10481053
// MIPS64BE:#define _MIPS_SZPTR 64
@@ -1253,6 +1258,7 @@
12531258
// MIPS64EL:#define _MIPS_ARCH_MIPS64R2 1
12541259
// MIPS64EL:#define _MIPS_FPSET 32
12551260
// MIPS64EL:#define _MIPS_SIM _ABI64
1261+
// MIPS64EL:#define _MIPS_SPFPSET 32
12561262
// MIPS64EL:#define _MIPS_SZINT 32
12571263
// MIPS64EL:#define _MIPS_SZLONG 64
12581264
// MIPS64EL:#define _MIPS_SZPTR 64
@@ -1506,6 +1512,7 @@
15061512
// MIPS-ARCH-32R6:#define _MIPS_ARCH "mips32r6"
15071513
// MIPS-ARCH-32R6:#define _MIPS_ARCH_MIPS32R6 1
15081514
// MIPS-ARCH-32R6:#define _MIPS_ISA _MIPS_ISA_MIPS32
1515+
// MIPS-ARCH-32R6:#define __mips_fpr 64
15091516
// MIPS-ARCH-32R6:#define __mips_isa_rev 6
15101517

15111518
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \
@@ -1682,14 +1689,28 @@
16821689
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-NOFP %s
16831690
// MIPS32-NOFP:#define __mips_fpr 0
16841691

1692+
// RUN: %clang_cc1 -target-feature -nooddspreg \
1693+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
1694+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-NOFP-ODD %s
1695+
// MIPS32-NOFP-ODD:#define _MIPS_SPFPSET 32
1696+
// MIPS32-NOFP-ODD:#define __mips_fpr 0
1697+
1698+
// RUN: %clang_cc1 -target-feature +nooddspreg -target-feature -fp64 \
1699+
// RUN: -E -dM -triple=mips-none-none < /dev/null \
1700+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-FP64-NOODD %s
1701+
// MIPS32-FP64-NOODD:#define _MIPS_SPFPSET 16
1702+
// MIPS32-FP64-NOODD:#define __mips_fpr 32
1703+
16851704
// RUN: %clang_cc1 -target-feature +fpxx \
16861705
// RUN: -E -dM -triple=mips-none-none < /dev/null \
16871706
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-MFPXX %s
1707+
// MIPS32-MFPXX:#define _MIPS_SPFPSET 16
16881708
// MIPS32-MFPXX:#define __mips_fpr 0
16891709

16901710
// RUN: %clang_cc1 -target-cpu mips32r6 -target-feature +fpxx \
16911711
// RUN: -E -dM -triple=mips-none-none < /dev/null \
16921712
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32R6-MFPXX %s
1713+
// MIPS32R6-MFPXX:#define _MIPS_SPFPSET 16
16931714
// MIPS32R6-MFPXX:#define __mips_fpr 0
16941715

16951716
// RUN: %clang_cc1 \
@@ -1716,30 +1737,35 @@
17161737
// RUN: -E -dM -triple=mips-none-none < /dev/null \
17171738
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-MFP32 %s
17181739
// MIPS32-MFP32:#define _MIPS_FPSET 16
1740+
// MIPS32-MFP32:#define _MIPS_SPFPSET 32
17191741
// MIPS32-MFP32:#define __mips_fpr 32
17201742

17211743
// RUN: %clang_cc1 -target-feature +fp64 \
17221744
// RUN: -E -dM -triple=mips-none-none < /dev/null \
17231745
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-MFP64 %s
17241746
// MIPS32-MFP64:#define _MIPS_FPSET 32
1747+
// MIPS32-MFP64:#define _MIPS_SPFPSET 32
17251748
// MIPS32-MFP64:#define __mips_fpr 64
17261749
//
17271750
// RUN: %clang_cc1 -target-feature +single-float \
17281751
// RUN: -E -dM -triple=mips-none-none < /dev/null \
17291752
// RUN: | FileCheck -match-full-lines -check-prefix MIPS32-MFP32SF %s
17301753
// MIPS32-MFP32SF:#define _MIPS_FPSET 32
1754+
// MIPS32-MFP32SF:#define _MIPS_SPFPSET 16
17311755
// MIPS32-MFP32SF:#define __mips_fpr 0
17321756

17331757
// RUN: %clang_cc1 -target-feature +fp64 \
17341758
// RUN: -E -dM -triple=mips64-none-none < /dev/null \
17351759
// RUN: | FileCheck -match-full-lines -check-prefix MIPS64-MFP64 %s
17361760
// MIPS64-MFP64:#define _MIPS_FPSET 32
1761+
// MIPS64-MFP64:#define _MIPS_SPFPSET 32
17371762
// MIPS64-MFP64:#define __mips_fpr 64
17381763

17391764
// RUN: %clang_cc1 -target-feature -fp64 -target-feature +single-float \
17401765
// RUN: -E -dM -triple=mips64-none-none < /dev/null \
17411766
// RUN: | FileCheck -match-full-lines -check-prefix MIPS64-NOMFP64 %s
17421767
// MIPS64-NOMFP64:#define _MIPS_FPSET 32
1768+
// MIPS64-NOMFP64:#define _MIPS_SPFPSET 32
17431769
// MIPS64-NOMFP64:#define __mips_fpr 32
17441770

17451771
// RUN: %clang_cc1 -target-cpu mips32r6 \
@@ -1749,6 +1775,7 @@
17491775
// RUN: -E -dM -triple=mips64-none-none < /dev/null \
17501776
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-XXR6 %s
17511777
// MIPS-XXR6:#define _MIPS_FPSET 32
1778+
// MIPS-XXR6:#define _MIPS_SPFPSET 32
17521779
// MIPS-XXR6:#define __mips_fpr 64
17531780
// MIPS-XXR6:#define __mips_nan2008 1
17541781

0 commit comments

Comments
 (0)