[clang] b55186e - [clang][Driver] Define soft float macros for PPC. (#106012)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 19:07:38 PDT 2024


Author: Alex Rønne Petersen
Date: 2024-09-04T10:07:35+08:00
New Revision: b55186eefd73b3848e01c8471c47a9354969d652

URL: https://github.com/llvm/llvm-project/commit/b55186eefd73b3848e01c8471c47a9354969d652
DIFF: https://github.com/llvm/llvm-project/commit/b55186eefd73b3848e01c8471c47a9354969d652.diff

LOG: [clang][Driver] Define soft float macros for PPC. (#106012)

Fixes #105972.

Co-authored-by: Qiu Chaofan <qcf at ecnelises.com>

Added: 
    

Modified: 
    clang/lib/Basic/Targets/PPC.cpp
    clang/lib/Basic/Targets/PPC.h
    clang/test/Preprocessor/init-ppc.c
    clang/test/Preprocessor/init-ppc64.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 04dc436eb1b9cd..1448069173b5f4 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -68,6 +68,10 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
       HasSPE = true;
       LongDoubleWidth = LongDoubleAlign = 64;
       LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+    } else if (Feature == "+frsqrte") {
+      HasFrsqrte = true;
+    } else if (Feature == "+frsqrtes") {
+      HasFrsqrtes = true;
     } else if (Feature == "-hard-float") {
       FloatABI = SoftFloat;
     } else if (Feature == "+paired-vector-memops") {
@@ -402,9 +406,18 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
     Builder.defineMacro("__VEC__", "10206");
     Builder.defineMacro("__ALTIVEC__");
   }
-  if (HasSPE) {
+  if (HasSPE)
     Builder.defineMacro("__SPE__");
+  if (HasSPE || FloatABI == SoftFloat)
     Builder.defineMacro("__NO_FPRS__");
+  if (FloatABI == SoftFloat) {
+    Builder.defineMacro("_SOFT_FLOAT");
+    Builder.defineMacro("_SOFT_DOUBLE");
+  } else {
+    if (HasFrsqrte)
+      Builder.defineMacro("__RSQRTE__");
+    if (HasFrsqrtes)
+      Builder.defineMacro("__RSQRTEF__");
   }
   if (HasVSX)
     Builder.defineMacro("__VSX__");
@@ -439,14 +452,10 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
   // FIXME: The following are not yet generated here by Clang, but are
   //        generated by GCC:
   //
-  //   _SOFT_FLOAT_
   //   __RECIP_PRECISION__
   //   __APPLE_ALTIVEC__
   //   __RECIP__
   //   __RECIPF__
-  //   __RSQRTE__
-  //   __RSQRTEF__
-  //   _SOFT_DOUBLE_
   //   __NO_LWSYNC__
   //   __CMODEL_MEDIUM__
   //   __CMODEL_LARGE__

diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 6d5d8dd54d013e..b0833d30550af4 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -73,6 +73,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
   bool HasExtDiv = false;
   bool HasP9Vector = false;
   bool HasSPE = false;
+  bool HasFrsqrte = false;
+  bool HasFrsqrtes = false;
   bool PairedVectorMemops = false;
   bool HasP10Vector = false;
   bool HasPCRelativeMemops = false;

diff  --git a/clang/test/Preprocessor/init-ppc.c b/clang/test/Preprocessor/init-ppc.c
index 3fb642af9d7420..1421b102a3dfdf 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -977,3 +977,21 @@
 
 // RUN: %clang_cc1 -E -dM -triple=powerpc-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix PPC-OPENBSD-CXX %s
 // PPC-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix PPCPWR4-RSQRT %s
+//
+// PPCPWR4-RSQRT-NOT:#define __RSQRTEF__ 1
+// PPCPWR4-RSQRT-NOT:#define __RSQRTE__ 1
+//
+// 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
+//
+// PPCPWR5-RSQRT:#define __RSQRTEF__ 1
+// PPCPWR5-RSQRT:#define __RSQRTE__ 1
+
+// 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
+//
+// PPC-SOFTFLT:#define _SOFT_DOUBLE 1
+// PPC-SOFTFLT:#define _SOFT_FLOAT 1
+// PPC-SOFTFLT:#define __NO_FPRS__ 1
+// PPC-SOFTFLT-NOT:#define __RSQRTE__ 1
+// PPC-SOFTFLT-NOT:#define __RSQRTEF__ 1

diff  --git a/clang/test/Preprocessor/init-ppc64.c b/clang/test/Preprocessor/init-ppc64.c
index 56164beb913d5c..57e2ca31d5d535 100644
--- a/clang/test/Preprocessor/init-ppc64.c
+++ b/clang/test/Preprocessor/init-ppc64.c
@@ -1110,3 +1110,21 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-FREEBSD %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-freebsd < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-FREEBSD %s
 // PPC64-FREEBSD-NOT: #define __LONG_DOUBLE_128__ 1
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none < /dev/null | FileCheck -match-full-lines -check-prefix PPC64PWR4-RSQRT %s
+//
+// PPC64PWR4-RSQRT-NOT:#define __RSQRTEF__ 1
+// PPC64PWR4-RSQRT-NOT:#define __RSQRTE__ 1
+//
+// 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
+//
+// PPC64PWR5-RSQRT:#define __RSQRTEF__ 1
+// PPC64PWR5-RSQRT:#define __RSQRTE__ 1
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -target-feature -hard-float -xc /dev/null | FileCheck --check-prefix=PPC64-SOFTFLT %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-linux-gnu -target-feature -hard-float -xc /dev/null | FileCheck --check-prefix=PPC64-SOFTFLT %s
+// PPC64-SOFTFLT:#define _SOFT_DOUBLE 1
+// PPC64-SOFTFLT:#define _SOFT_FLOAT 1
+// PPC64-SOFTFLT:#define __NO_FPRS__ 1
+// PPC64-SOFTFLT-NOT:#define __RSQRTE__ 1
+// PPC64-SOFTFLT-NOT:#define __RSQRTEF__ 1


        


More information about the cfe-commits mailing list