[clang] d11ec6f - [Clang] Enable IC/IF mode for __ibm128

Qiu Chaofan via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 11 02:41:09 PDT 2021


Author: Qiu Chaofan
Date: 2021-10-11T17:38:04+08:00
New Revision: d11ec6f67e45c630ab87bfb6010dcc93e89542fc

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

LOG: [Clang] Enable IC/IF mode for __ibm128

As for 128-bit floating points on PowerPC, compiler should have three
machine modes:

- IFmode, always IBM extended double
- KFmode, always IEEE 754R 128-bit floating point
- TFmode, matches the semantics for long double

This commit adds support for IF mode with its complex variant, IC mode.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D109950

Added: 
    

Modified: 
    clang/lib/Basic/TargetInfo.cpp
    clang/lib/Sema/SemaDeclAttr.cpp
    clang/test/CodeGenCXX/ibm128-declarations.cpp
    clang/test/Sema/attr-mode.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 2d9110a5fc447..514893b47b4f4 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -297,11 +297,11 @@ FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth,
     if (ExplicitType == FloatModeKind::Float128)
       return hasFloat128Type() ? FloatModeKind::Float128
                                : FloatModeKind::NoFloat;
-    if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
-        &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
-      return FloatModeKind::LongDouble;
-    if (hasFloat128Type())
-      return FloatModeKind::Float128;
+    if (ExplicitType == FloatModeKind::Ibm128)
+      return hasIbm128Type() ? FloatModeKind::Ibm128
+                             : FloatModeKind::NoFloat;
+    if (ExplicitType == FloatModeKind::LongDouble)
+      return ExplicitType;
     break;
   }
 

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1b9a63c15e71e..cd50818d10638 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4233,6 +4233,10 @@ static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth,
       ExplicitType = FloatModeKind::LongDouble;
       DestWidth = 128;
       break;
+    case 'I':
+      ExplicitType = FloatModeKind::Ibm128;
+      DestWidth = Str[1] == 'I' ? 0 : 128;
+      break;
     }
     if (Str[1] == 'F') {
       IntegerMode = false;

diff  --git a/clang/test/CodeGenCXX/ibm128-declarations.cpp b/clang/test/CodeGenCXX/ibm128-declarations.cpp
index 7ff23aa1e0f85..6d2c6d2544879 100644
--- a/clang/test/CodeGenCXX/ibm128-declarations.cpp
+++ b/clang/test/CodeGenCXX/ibm128-declarations.cpp
@@ -59,6 +59,12 @@ template <__ibm128 Q> struct T2 {
   constexpr static __ibm128 mem = Q;
 };
 
+typedef float w128ibm __attribute__((mode(IF)));
+typedef _Complex float w128ibm_c __attribute__((mode(IC)));
+
+w128ibm icmode_self(w128ibm x) { return x; }
+w128ibm_c icmode_self_complex(w128ibm_c x) { return x; }
+
 int main(void) {
   __ibm128 lf;
   CTest ct(lf);
@@ -115,6 +121,9 @@ int main(void) {
 // CHECK:   ret ppc_fp128 %2
 // CHECK: }
 
+// CHECK: define dso_local ppc_fp128 @_Z11icmode_selfg(ppc_fp128 %x)
+// CHECK: define dso_local { ppc_fp128, ppc_fp128 } @_Z19icmode_self_complexCg(ppc_fp128 %x.coerce0, ppc_fp128 %x.coerce1)
+
 // CHECK: define dso_local signext i32 @main()
 // CHECK: entry:
 // CHECK:   %0 = load ppc_fp128, ppc_fp128* %lf, align 16

diff  --git a/clang/test/Sema/attr-mode.c b/clang/test/Sema/attr-mode.c
index a4bac90b99fb8..c89738a9d7969 100644
--- a/clang/test/Sema/attr-mode.c
+++ b/clang/test/Sema/attr-mode.c
@@ -92,6 +92,12 @@ void f_ft128_arg(long double *x);
 void f_ft128_complex_arg(_Complex long double *x);
 void test_TFtype(f128ibm *a) { f_ft128_arg (a); }
 void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); }
+typedef float w128ibm __attribute__((mode(IF)));
+typedef _Complex float cw128ibm __attribute__((mode(IC)));
+void f_ibm128_arg(__ibm128 *x);
+void f_ibm128_complex_arg(_Complex __ibm128 *x);
+void test_IFtype(w128ibm *a) { f_ibm128_arg(a); }
+void test_ICtype(cw128ibm *a) { f_ibm128_complex_arg(a); }
 #elif TEST_F128_PPC64
 typedef int invalid_7 __attribute((mode(KF))); // expected-error{{type of machine mode does not match type of base type}}
 typedef int invalid_8 __attribute((mode(KI))); // expected-error{{unknown machine mode}}


        


More information about the cfe-commits mailing list