Skip to content

Commit 0461534

Browse files
committed
[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 llvm-svn: 365480
1 parent 51dad41 commit 0461534

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

clang/include/clang/Basic/TargetInfo.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,11 @@ class TargetInfo : public virtual TransferrableTargetInfo,
599599
return *Float128Format;
600600
}
601601

602-
/// Return true if the 'long double' type should be mangled like
603-
/// __float128.
604-
virtual bool useFloat128ManglingForLongDouble() const { return false; }
602+
/// Return the mangled code of long double.
603+
virtual const char *getLongDoubleMangling() const { return "e"; }
604+
605+
/// Return the mangled code of __float128.
606+
virtual const char *getFloat128Mangling() const { return "g"; }
605607

606608
/// Return the value for the C99 FLT_EVAL_METHOD macro.
607609
virtual unsigned getFloatEvalMethod() const { return 0; }

clang/lib/AST/ItaniumMangle.cpp

+10-21
Original file line numberDiff line numberDiff line change
@@ -2608,30 +2608,19 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
26082608
Out << 'd';
26092609
break;
26102610
case BuiltinType::LongDouble: {
2611-
bool UseFloat128Mangling =
2612-
getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
2613-
if (getASTContext().getLangOpts().OpenMP &&
2614-
getASTContext().getLangOpts().OpenMPIsDevice) {
2615-
UseFloat128Mangling = getASTContext()
2616-
.getAuxTargetInfo()
2617-
->useFloat128ManglingForLongDouble();
2618-
}
2619-
Out << (UseFloat128Mangling ? 'g' : 'e');
2611+
const TargetInfo *TI = getASTContext().getLangOpts().OpenMP &&
2612+
getASTContext().getLangOpts().OpenMPIsDevice
2613+
? getASTContext().getAuxTargetInfo()
2614+
: &getASTContext().getTargetInfo();
2615+
Out << TI->getLongDoubleMangling();
26202616
break;
26212617
}
26222618
case BuiltinType::Float128: {
2623-
bool UseFloat128Mangling =
2624-
getASTContext().getTargetInfo().useFloat128ManglingForLongDouble();
2625-
if (getASTContext().getLangOpts().OpenMP &&
2626-
getASTContext().getLangOpts().OpenMPIsDevice) {
2627-
UseFloat128Mangling = getASTContext()
2628-
.getAuxTargetInfo()
2629-
->useFloat128ManglingForLongDouble();
2630-
}
2631-
if (UseFloat128Mangling)
2632-
Out << "U10__float128"; // Match the GCC mangling
2633-
else
2634-
Out << 'g';
2619+
const TargetInfo *TI = getASTContext().getLangOpts().OpenMP &&
2620+
getASTContext().getLangOpts().OpenMPIsDevice
2621+
? getASTContext().getAuxTargetInfo()
2622+
: &getASTContext().getTargetInfo();
2623+
Out << TI->getFloat128Mangling();
26352624
break;
26362625
}
26372626
case BuiltinType::NullPtr:

clang/lib/Basic/Targets/PPC.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
314314

315315
bool hasSjLjLowering() const override { return true; }
316316

317-
bool useFloat128ManglingForLongDouble() const override {
318-
return LongDoubleWidth == 128 &&
319-
LongDoubleFormat == &llvm::APFloat::PPCDoubleDouble() &&
320-
getTriple().isOSBinFormatELF();
317+
const char *getLongDoubleMangling() const override {
318+
if (LongDoubleWidth == 64)
319+
return "e";
320+
return LongDoubleFormat == &llvm::APFloat::PPCDoubleDouble()
321+
? "g"
322+
: "u9__ieee128";
321323
}
324+
const char *getFloat128Mangling() const override { return "u9__ieee128"; }
322325
};
323326

324327
class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public PPCTargetInfo {

clang/lib/Basic/Targets/SystemZ.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
141141
return "";
142142
}
143143

144-
bool useFloat128ManglingForLongDouble() const override { return true; }
144+
const char *getLongDoubleMangling() const override { return "g"; }
145145
};
146146
} // namespace targets
147147
} // namespace clang

clang/lib/Basic/Targets/X86.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo
848848
LongDoubleFormat = &llvm::APFloat::IEEEquad();
849849
}
850850

851-
bool useFloat128ManglingForLongDouble() const override { return true; }
851+
const char *getLongDoubleMangling() const override { return "g"; }
852852
};
853853
} // namespace targets
854854
} // namespace clang

clang/test/CodeGenCXX/float128-declarations.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ int main(void) {
8484
// CHECK-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global fp128 0xL00000000000000004004080000000000
8585
// CHECK-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x fp128]
8686
// CHECK-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x fp128] [fp128 0xL33333333333333333FFF333333333333, fp128 0xL00000000000000004000800000000000, fp128 0xL00000000000000004025176592E00000]
87-
// CHECK-DAG: define internal fp128 @_ZN12_GLOBAL__N_16func1nERKU10__float128(fp128*
87+
// CHECK-DAG: define internal fp128 @_ZN12_GLOBAL__N_16func1nERKu9__ieee128(fp128*
8888
// CHECK-DAG: @f1f = global fp128 0xL00000000000000000000000000000000
8989
// CHECK-DAG: @f2f = global fp128 0xL33333333333333334004033333333333
9090
// CHECK-DAG: @arr1f = global [10 x fp128]
9191
// CHECK-DAG: @arr2f = global [3 x fp128] [fp128 0xL3333333333333333BFFF333333333333, fp128 0xL0000000000000000C000800000000000, fp128 0xL0000000000000000C025176592E00000]
92-
// CHECK-DAG: declare fp128 @_Z6func1fU10__float128(fp128)
93-
// CHECK-DAG: define linkonce_odr void @_ZN2C1C2EU10__float128(%class.C1* %this, fp128 %arg)
94-
// CHECK-DAG: define linkonce_odr fp128 @_ZN2C16func2cEU10__float128(fp128 %arg)
95-
// CHECK-DAG: define linkonce_odr fp128 @_Z6func1tIU10__float128ET_S0_(fp128 %arg)
92+
// CHECK-DAG: declare fp128 @_Z6func1fu9__ieee128(fp128)
93+
// CHECK-DAG: define linkonce_odr void @_ZN2C1C2Eu9__ieee128(%class.C1* %this, fp128 %arg)
94+
// CHECK-DAG: define linkonce_odr fp128 @_ZN2C16func2cEu9__ieee128(fp128 %arg)
95+
// CHECK-DAG: define linkonce_odr fp128 @_Z6func1tIu9__ieee128ET_S0_(fp128 %arg)
9696
// CHECK-DAG: @__const.main.s1 = private unnamed_addr constant %struct.S1 { fp128 0xL00000000000000004006080000000000 }
9797
// CHECK-DAG: store fp128 0xLF0AFD0EBFF292DCE42E0B38CDD83F26F, fp128* %f1l, align 16
9898
// CHECK-DAG: store fp128 0xL00000000000000008000000000000000, fp128* %f2l, align 16

0 commit comments

Comments
 (0)