r365480 - [ItaniumMangle] Refactor long double/__float128 mangling and fix the mangled code

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 9 06:32:27 PDT 2019


Author: maskray
Date: Tue Jul  9 06:32:26 2019
New Revision: 365480

URL: http://llvm.org/viewvc/llvm-project?rev=365480&view=rev
Log:
[ItaniumMangle] Refactor long double/__float128 mangling and fix the mangled code

In gcc PowerPC, long double has 3 mangling schemes:

-mlong-double-64: `e`
-mlong-double-128 -mabi=ibmlongdouble: `g`
-mlong-double-128 -mabi=ieeelongdouble: `u9__ieee128` (gcc <= 8.1: `U10__float128`)

The current useFloat128ManglingForLongDouble() bisection is not suitable
when we support -mlong-double-128 in clang (D64277). Replace
useFloat128ManglingForLongDouble() with getLongDoubleMangling() and
getFloat128Mangling() to allow 3 mangling schemes.

I also deleted the `getTriple().isOSBinFormatELF()` check (the Darwin
support has gone: https://reviews.llvm.org/D50988).

For x86, change the mangled code of __float128 from `U10__float128` to `g`. `U10__float128` was wrongly copied from PowerPC.
The test will be added to `test/CodeGen/x86-long-double.cpp` in D64277.

Reviewed By: erichkeane

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

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/AST/ItaniumMangle.cpp
    cfe/trunk/lib/Basic/Targets/PPC.h
    cfe/trunk/lib/Basic/Targets/SystemZ.h
    cfe/trunk/lib/Basic/Targets/X86.h
    cfe/trunk/test/CodeGenCXX/float128-declarations.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Jul  9 06:32:26 2019
@@ -599,9 +599,11 @@ public:
     return *Float128Format;
   }
 
-  /// Return true if the 'long double' type should be mangled like
-  /// __float128.
-  virtual bool useFloat128ManglingForLongDouble() const { return false; }
+  /// Return the mangled code of long double.
+  virtual const char *getLongDoubleMangling() const { return "e"; }
+
+  /// Return the mangled code of __float128.
+  virtual const char *getFloat128Mangling() const { return "g"; }
 
   /// Return the value for the C99 FLT_EVAL_METHOD macro.
   virtual unsigned getFloatEvalMethod() const { return 0; }

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Tue Jul  9 06:32:26 2019
@@ -2608,30 +2608,19 @@ void CXXNameMangler::mangleType(const Bu
     Out << 'd';
     break;
   case BuiltinType::LongDouble: {
-    bool UseFloat128Mangling =
-        getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
-    if (getASTContext().getLangOpts().OpenMP &&
-        getASTContext().getLangOpts().OpenMPIsDevice) {
-      UseFloat128Mangling = getASTContext()
-                                .getAuxTargetInfo()
-                                ->useFloat128ManglingForLongDouble();
-    }
-    Out << (UseFloat128Mangling ? 'g' : 'e');
+    const TargetInfo *TI = getASTContext().getLangOpts().OpenMP &&
+                                   getASTContext().getLangOpts().OpenMPIsDevice
+                               ? getASTContext().getAuxTargetInfo()
+                               : &getASTContext().getTargetInfo();
+    Out << TI->getLongDoubleMangling();
     break;
   }
   case BuiltinType::Float128: {
-    bool UseFloat128Mangling =
-        getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
-    if (getASTContext().getLangOpts().OpenMP &&
-        getASTContext().getLangOpts().OpenMPIsDevice) {
-      UseFloat128Mangling = getASTContext()
-                                .getAuxTargetInfo()
-                                ->useFloat128ManglingForLongDouble();
-    }
-    if (UseFloat128Mangling)
-      Out << "U10__float128"; // Match the GCC mangling
-    else
-      Out << 'g';
+    const TargetInfo *TI = getASTContext().getLangOpts().OpenMP &&
+                                   getASTContext().getLangOpts().OpenMPIsDevice
+                               ? getASTContext().getAuxTargetInfo()
+                               : &getASTContext().getTargetInfo();
+    Out << TI->getFloat128Mangling();
     break;
   }
   case BuiltinType::NullPtr:

Modified: cfe/trunk/lib/Basic/Targets/PPC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.h?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/PPC.h (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.h Tue Jul  9 06:32:26 2019
@@ -314,11 +314,14 @@ public:
 
   bool hasSjLjLowering() const override { return true; }
 
-  bool useFloat128ManglingForLongDouble() const override {
-    return LongDoubleWidth == 128 &&
-           LongDoubleFormat == &llvm::APFloat::PPCDoubleDouble() &&
-           getTriple().isOSBinFormatELF();
+  const char *getLongDoubleMangling() const override {
+    if (LongDoubleWidth == 64)
+      return "e";
+    return LongDoubleFormat == &llvm::APFloat::PPCDoubleDouble()
+               ? "g"
+               : "u9__ieee128";
   }
+  const char *getFloat128Mangling() const override { return "u9__ieee128"; }
 };
 
 class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public PPCTargetInfo {

Modified: cfe/trunk/lib/Basic/Targets/SystemZ.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/SystemZ.h?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/SystemZ.h (original)
+++ cfe/trunk/lib/Basic/Targets/SystemZ.h Tue Jul  9 06:32:26 2019
@@ -141,7 +141,7 @@ public:
     return "";
   }
 
-  bool useFloat128ManglingForLongDouble() const override { return true; }
+  const char *getLongDoubleMangling() const override { return "g"; }
 };
 } // namespace targets
 } // namespace clang

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Tue Jul  9 06:32:26 2019
@@ -848,7 +848,7 @@ public:
     LongDoubleFormat = &llvm::APFloat::IEEEquad();
   }
 
-  bool useFloat128ManglingForLongDouble() const override { return true; }
+  const char *getLongDoubleMangling() const override { return "g"; }
 };
 } // namespace targets
 } // namespace clang

Modified: cfe/trunk/test/CodeGenCXX/float128-declarations.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/float128-declarations.cpp?rev=365480&r1=365479&r2=365480&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/float128-declarations.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/float128-declarations.cpp Tue Jul  9 06:32:26 2019
@@ -84,15 +84,15 @@ int main(void) {
 // CHECK-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global fp128 0xL00000000000000004004080000000000
 // CHECK-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x fp128]
 // CHECK-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x fp128] [fp128 0xL33333333333333333FFF333333333333, fp128 0xL00000000000000004000800000000000, fp128 0xL00000000000000004025176592E00000]
-// CHECK-DAG: define internal fp128 @_ZN12_GLOBAL__N_16func1nERKU10__float128(fp128*
+// CHECK-DAG: define internal fp128 @_ZN12_GLOBAL__N_16func1nERKu9__ieee128(fp128*
 // CHECK-DAG: @f1f = global fp128 0xL00000000000000000000000000000000
 // CHECK-DAG: @f2f = global fp128 0xL33333333333333334004033333333333
 // CHECK-DAG: @arr1f = global [10 x fp128]
 // CHECK-DAG: @arr2f = global [3 x fp128] [fp128 0xL3333333333333333BFFF333333333333, fp128 0xL0000000000000000C000800000000000, fp128 0xL0000000000000000C025176592E00000]
-// CHECK-DAG: declare fp128 @_Z6func1fU10__float128(fp128)
-// CHECK-DAG: define linkonce_odr void @_ZN2C1C2EU10__float128(%class.C1* %this, fp128 %arg)
-// CHECK-DAG: define linkonce_odr fp128 @_ZN2C16func2cEU10__float128(fp128 %arg)
-// CHECK-DAG: define linkonce_odr fp128 @_Z6func1tIU10__float128ET_S0_(fp128 %arg)
+// CHECK-DAG: declare fp128 @_Z6func1fu9__ieee128(fp128)
+// CHECK-DAG: define linkonce_odr void @_ZN2C1C2Eu9__ieee128(%class.C1* %this, fp128 %arg)
+// CHECK-DAG: define linkonce_odr fp128 @_ZN2C16func2cEu9__ieee128(fp128 %arg)
+// CHECK-DAG: define linkonce_odr fp128 @_Z6func1tIu9__ieee128ET_S0_(fp128 %arg)
 // CHECK-DAG: @__const.main.s1 = private unnamed_addr constant %struct.S1 { fp128 0xL00000000000000004006080000000000 }
 // CHECK-DAG: store fp128 0xLF0AFD0EBFF292DCE42E0B38CDD83F26F, fp128* %f1l, align 16
 // CHECK-DAG: store fp128 0xL00000000000000008000000000000000, fp128* %f2l, align 16




More information about the cfe-commits mailing list