Skip to content

Commit 33a6c74

Browse files
committed
[llvm][clang] Move long double layout logic from clang to LLVM
Information about the size and alignment of `long double` is currently part of clang. Move this logic to LLVM so it can be used to control lowering of intrinsics.
1 parent 590f492 commit 33a6c74

File tree

20 files changed

+184
-90
lines changed

20 files changed

+184
-90
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,12 @@ class TargetInfo : public TransferrableTargetInfo,
12181218
return Triple;
12191219
}
12201220

1221+
/// Returns information about C layouts that come from LLVM. This is used
1222+
/// to control lowering to libcalls.
1223+
llvm::Triple::CLayouts getTripleLayouts() const {
1224+
return Triple.getCLayouts();
1225+
}
1226+
12211227
/// Returns the target ID if supported.
12221228
virtual std::optional<std::string> getTargetID() const {
12231229
return std::nullopt;

clang/lib/Basic/TargetInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ static const LangASMap FakeAddrSpaceMap = {
5454
TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
5555
// Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
5656
// SPARC. These should be overridden by concrete targets as needed.
57+
58+
// Load some defaults from LLVM
59+
llvm::Triple::CLayouts TripleLayouts = getTripleLayouts();
60+
5761
BigEndian = !T.isLittleEndian();
5862
TLSSupported = true;
5963
VLASupported = true;
@@ -113,8 +117,8 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
113117
FloatAlign = 32;
114118
DoubleWidth = 64;
115119
DoubleAlign = 64;
116-
LongDoubleWidth = 64;
117-
LongDoubleAlign = 64;
120+
LongDoubleWidth = TripleLayouts.LongDoubleWidth;
121+
LongDoubleAlign = TripleLayouts.LongDoubleAlign;
118122
Float128Align = 128;
119123
Ibm128Align = 128;
120124
LargeArrayMinWidth = 0;
@@ -144,7 +148,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
144148
HalfFormat = &llvm::APFloat::IEEEhalf();
145149
FloatFormat = &llvm::APFloat::IEEEsingle();
146150
DoubleFormat = &llvm::APFloat::IEEEdouble();
147-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
151+
LongDoubleFormat = TripleLayouts.LongDoubleFormat;
148152
Float128Format = &llvm::APFloat::IEEEquad();
149153
Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
150154
MCountName = "mcount";

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
156156
MaxAtomicInlineWidth = 128;
157157
MaxAtomicPromoteWidth = 128;
158158

159-
LongDoubleWidth = LongDoubleAlign = SuitableAlign = 128;
160-
LongDoubleFormat = &llvm::APFloat::IEEEquad();
159+
SuitableAlign = LongDoubleAlign;
161160

162161
BFloat16Width = BFloat16Align = 16;
163162
BFloat16Format = &llvm::APFloat::BFloat();
@@ -1452,8 +1451,6 @@ WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
14521451
IntWidth = IntAlign = 32;
14531452
LongWidth = LongAlign = 32;
14541453
DoubleAlign = LongLongAlign = 64;
1455-
LongDoubleWidth = LongDoubleAlign = 64;
1456-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
14571454
IntMaxType = SignedLongLong;
14581455
Int64Type = SignedLongLong;
14591456
SizeType = UnsignedLongLong;
@@ -1550,8 +1547,7 @@ DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
15501547
WCharType = SignedInt;
15511548
UseSignedCharForObjCBool = false;
15521549

1553-
LongDoubleWidth = LongDoubleAlign = SuitableAlign = 64;
1554-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
1550+
SuitableAlign = LongDoubleAlign;
15551551

15561552
UseZeroLengthBitfieldAlignment = false;
15571553

clang/lib/Basic/Targets/ARC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LLVM_LIBRARY_VISIBILITY ARCTargetInfo : public TargetInfo {
2828
NoAsmVariants = true;
2929
LongLongAlign = 32;
3030
SuitableAlign = 32;
31-
DoubleAlign = LongDoubleAlign = 32;
31+
DoubleAlign = 32;
3232
SizeType = UnsignedInt;
3333
PtrDiffType = SignedInt;
3434
IntPtrType = SignedInt;

clang/lib/Basic/Targets/AVR.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
4444
DoubleWidth = 32;
4545
DoubleAlign = 8;
4646
DoubleFormat = &llvm::APFloat::IEEEsingle();
47-
LongDoubleWidth = 32;
48-
LongDoubleAlign = 8;
49-
LongDoubleFormat = &llvm::APFloat::IEEEsingle();
5047
SizeType = UnsignedInt;
5148
PtrDiffType = SignedInt;
5249
IntPtrType = SignedInt;

clang/lib/Basic/Targets/CSKY.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {
4343
NoAsmVariants = true;
4444
LongLongAlign = 32;
4545
SuitableAlign = 32;
46-
DoubleAlign = LongDoubleAlign = 32;
46+
DoubleAlign = 32;
4747
SizeType = UnsignedInt;
4848
PtrDiffType = SignedInt;
4949
IntPtrType = SignedInt;

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
3737
HasFeatureF = false;
3838
HasFeatureLSX = false;
3939
HasFeatureLASX = false;
40-
LongDoubleWidth = 128;
41-
LongDoubleAlign = 128;
42-
LongDoubleFormat = &llvm::APFloat::IEEEquad();
4340
MCountName = "_mcount";
4441
SuitableAlign = 128;
4542
WCharType = SignedInt;

clang/lib/Basic/Targets/MSP430.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class LLVM_LIBRARY_VISIBILITY MSP430TargetInfo : public TargetInfo {
3535
LongAlign = LongLongAlign = 16;
3636
FloatWidth = 32;
3737
FloatAlign = 16;
38-
DoubleWidth = LongDoubleWidth = 64;
39-
DoubleAlign = LongDoubleAlign = 16;
38+
DoubleWidth = 64;
39+
DoubleAlign = 16;
4040
PointerWidth = 16;
4141
PointerAlign = 16;
4242
SuitableAlign = 16;

clang/lib/Basic/Targets/Mips.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
118118
void setO32ABITypes() {
119119
Int64Type = SignedLongLong;
120120
IntMaxType = Int64Type;
121-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
122-
LongDoubleWidth = LongDoubleAlign = 64;
123121
LongWidth = LongAlign = 32;
124122
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
125123
PointerWidth = PointerAlign = 32;
@@ -129,12 +127,6 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
129127
}
130128

131129
void setN32N64ABITypes() {
132-
LongDoubleWidth = LongDoubleAlign = 128;
133-
LongDoubleFormat = &llvm::APFloat::IEEEquad();
134-
if (getTriple().isOSFreeBSD()) {
135-
LongDoubleWidth = LongDoubleAlign = 64;
136-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
137-
}
138130
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
139131
SuitableAlign = 128;
140132
}

clang/lib/Basic/Targets/PPC.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8888
PPCTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
8989
: TargetInfo(Triple) {
9090
SuitableAlign = 128;
91-
LongDoubleWidth = LongDoubleAlign = 128;
92-
LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
9391
HasStrictFP = true;
9492
HasIbm128 = true;
9593
}
@@ -384,20 +382,11 @@ class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public PPCTargetInfo {
384382
SizeType = UnsignedLong;
385383
PtrDiffType = SignedLong;
386384
IntPtrType = SignedLong;
387-
LongDoubleWidth = 64;
388-
LongDoubleAlign = DoubleAlign = 32;
389-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
390385
break;
391386
default:
392387
break;
393388
}
394389

395-
if (Triple.isOSFreeBSD() || Triple.isOSNetBSD() || Triple.isOSOpenBSD() ||
396-
Triple.isMusl()) {
397-
LongDoubleWidth = LongDoubleAlign = 64;
398-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
399-
}
400-
401390
// PPC32 supports atomics up to 4 bytes.
402391
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
403392
}
@@ -422,9 +411,6 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
422411
if (Triple.isOSAIX()) {
423412
// TODO: Set appropriate ABI for AIX platform.
424413
DataLayout = "E-m:a-Fi64-i64:64-n32:64";
425-
LongDoubleWidth = 64;
426-
LongDoubleAlign = DoubleAlign = 32;
427-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
428414
} else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
429415
DataLayout = "e-m:e-Fn32-i64:64-n32:64";
430416
ABI = "elfv2";
@@ -440,11 +426,6 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
440426
DataLayout += "-i64:64-n32:64";
441427
}
442428

443-
if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) {
444-
LongDoubleWidth = LongDoubleAlign = 64;
445-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
446-
}
447-
448429
if (Triple.isOSAIX() || Triple.isOSLinux())
449430
DataLayout += "-S128-v256:256:256-v512:512:512";
450431
resetDataLayout(DataLayout);

0 commit comments

Comments
 (0)