Skip to content

Commit

Permalink
[ItaniumMangle] Refactor long double/__float128 mangling and fix the …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MaskRay committed Jul 9, 2019
1 parent 51dad41 commit 0461534
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/TargetInfo.h
Expand Up @@ -599,9 +599,11 @@ class TargetInfo : public virtual TransferrableTargetInfo,
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; }
Expand Down
31 changes: 10 additions & 21 deletions clang/lib/AST/ItaniumMangle.cpp
Expand Up @@ -2608,30 +2608,19 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
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:
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Basic/Targets/PPC.h
Expand Up @@ -314,11 +314,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {

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 {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/SystemZ.h
Expand Up @@ -141,7 +141,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
return "";
}

bool useFloat128ManglingForLongDouble() const override { return true; }
const char *getLongDoubleMangling() const override { return "g"; }
};
} // namespace targets
} // namespace clang
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/X86.h
Expand Up @@ -848,7 +848,7 @@ class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo
LongDoubleFormat = &llvm::APFloat::IEEEquad();
}

bool useFloat128ManglingForLongDouble() const override { return true; }
const char *getLongDoubleMangling() const override { return "g"; }
};
} // namespace targets
} // namespace clang
Expand Down
10 changes: 5 additions & 5 deletions clang/test/CodeGenCXX/float128-declarations.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 0461534

Please sign in to comment.