Skip to content

Commit b55186e

Browse files
alexrpecnelises
andauthored
[clang][Driver] Define soft float macros for PPC. (#106012)
Fixes #105972. Co-authored-by: Qiu Chaofan <[email protected]>
1 parent a27ff17 commit b55186e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
6868
HasSPE = true;
6969
LongDoubleWidth = LongDoubleAlign = 64;
7070
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
71+
} else if (Feature == "+frsqrte") {
72+
HasFrsqrte = true;
73+
} else if (Feature == "+frsqrtes") {
74+
HasFrsqrtes = true;
7175
} else if (Feature == "-hard-float") {
7276
FloatABI = SoftFloat;
7377
} else if (Feature == "+paired-vector-memops") {
@@ -402,9 +406,18 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
402406
Builder.defineMacro("__VEC__", "10206");
403407
Builder.defineMacro("__ALTIVEC__");
404408
}
405-
if (HasSPE) {
409+
if (HasSPE)
406410
Builder.defineMacro("__SPE__");
411+
if (HasSPE || FloatABI == SoftFloat)
407412
Builder.defineMacro("__NO_FPRS__");
413+
if (FloatABI == SoftFloat) {
414+
Builder.defineMacro("_SOFT_FLOAT");
415+
Builder.defineMacro("_SOFT_DOUBLE");
416+
} else {
417+
if (HasFrsqrte)
418+
Builder.defineMacro("__RSQRTE__");
419+
if (HasFrsqrtes)
420+
Builder.defineMacro("__RSQRTEF__");
408421
}
409422
if (HasVSX)
410423
Builder.defineMacro("__VSX__");
@@ -439,14 +452,10 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
439452
// FIXME: The following are not yet generated here by Clang, but are
440453
// generated by GCC:
441454
//
442-
// _SOFT_FLOAT_
443455
// __RECIP_PRECISION__
444456
// __APPLE_ALTIVEC__
445457
// __RECIP__
446458
// __RECIPF__
447-
// __RSQRTE__
448-
// __RSQRTEF__
449-
// _SOFT_DOUBLE_
450459
// __NO_LWSYNC__
451460
// __CMODEL_MEDIUM__
452461
// __CMODEL_LARGE__

clang/lib/Basic/Targets/PPC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
7373
bool HasExtDiv = false;
7474
bool HasP9Vector = false;
7575
bool HasSPE = false;
76+
bool HasFrsqrte = false;
77+
bool HasFrsqrtes = false;
7678
bool PairedVectorMemops = false;
7779
bool HasP10Vector = false;
7880
bool HasPCRelativeMemops = false;

clang/test/Preprocessor/init-ppc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,21 @@
977977

978978
// RUN: %clang_cc1 -E -dM -triple=powerpc-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix PPC-OPENBSD-CXX %s
979979
// PPC-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
980+
981+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix PPCPWR4-RSQRT %s
982+
//
983+
// PPCPWR4-RSQRT-NOT:#define __RSQRTEF__ 1
984+
// PPCPWR4-RSQRT-NOT:#define __RSQRTE__ 1
985+
//
986+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-none-none -target-feature +frsqrte -target-feature +frsqrtes < /dev/null | FileCheck -match-full-lines -check-prefix PPCPWR5-RSQRT %s
987+
//
988+
// PPCPWR5-RSQRT:#define __RSQRTEF__ 1
989+
// PPCPWR5-RSQRT:#define __RSQRTE__ 1
990+
991+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu -target-feature -hard-float < /dev/null | FileCheck -match-full-lines -check-prefix PPC-SOFTFLT %s
992+
//
993+
// PPC-SOFTFLT:#define _SOFT_DOUBLE 1
994+
// PPC-SOFTFLT:#define _SOFT_FLOAT 1
995+
// PPC-SOFTFLT:#define __NO_FPRS__ 1
996+
// PPC-SOFTFLT-NOT:#define __RSQRTE__ 1
997+
// PPC-SOFTFLT-NOT:#define __RSQRTEF__ 1

clang/test/Preprocessor/init-ppc64.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,3 +1110,21 @@
11101110
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-FREEBSD %s
11111111
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-freebsd < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-FREEBSD %s
11121112
// PPC64-FREEBSD-NOT: #define __LONG_DOUBLE_128__ 1
1113+
1114+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none < /dev/null | FileCheck -match-full-lines -check-prefix PPC64PWR4-RSQRT %s
1115+
//
1116+
// PPC64PWR4-RSQRT-NOT:#define __RSQRTEF__ 1
1117+
// PPC64PWR4-RSQRT-NOT:#define __RSQRTE__ 1
1118+
//
1119+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +frsqrte -target-feature +frsqrtes < /dev/null | FileCheck -match-full-lines -check-prefix PPC64PWR5-RSQRT %s
1120+
//
1121+
// PPC64PWR5-RSQRT:#define __RSQRTEF__ 1
1122+
// PPC64PWR5-RSQRT:#define __RSQRTE__ 1
1123+
1124+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -target-feature -hard-float -xc /dev/null | FileCheck --check-prefix=PPC64-SOFTFLT %s
1125+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-linux-gnu -target-feature -hard-float -xc /dev/null | FileCheck --check-prefix=PPC64-SOFTFLT %s
1126+
// PPC64-SOFTFLT:#define _SOFT_DOUBLE 1
1127+
// PPC64-SOFTFLT:#define _SOFT_FLOAT 1
1128+
// PPC64-SOFTFLT:#define __NO_FPRS__ 1
1129+
// PPC64-SOFTFLT-NOT:#define __RSQRTE__ 1
1130+
// PPC64-SOFTFLT-NOT:#define __RSQRTEF__ 1

0 commit comments

Comments
 (0)