Skip to content

Commit 9dc3255

Browse files
authored
[Clang] Use DataLayout from TargetParser (#171135)
This switches clang to use the data layouts from TargetParser, instead of maintaining its own copy of data layouts, which are required to match the backend data layouts. For now I've kept explicit calls to resetDataLayout(), just with the argument implied by the triple and ABI. Ideally this would happen automatically, but the way these classes are initialized currently doesn't offer a great place to do this. Previously resetDataLayout() also set the UserLabelPrefix. I've separated this out, with a reasonable default so that most targets don't need to worry about it. I've kept the explicit data layouts for TCE and SPIR (without the V). These seem to not correspond to real LLVM targets. I've also fixed the XCore data layout in TargetParser, which was incorrectly set to the same one as Xtensa. It was previously unused.
1 parent f1f3160 commit 9dc3255

File tree

31 files changed

+68
-296
lines changed

31 files changed

+68
-296
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ class TargetInfo : public TransferrableTargetInfo,
296296
// TargetInfo Constructor. Default initializes all fields.
297297
TargetInfo(const llvm::Triple &T);
298298

299-
// UserLabelPrefix must match DL's getGlobalPrefix() when interpreted
300-
// as a DataLayout object.
301-
void resetDataLayout(StringRef DL, const char *UserLabelPrefix = "");
299+
/// Set the data layout to the given string.
300+
void resetDataLayout(StringRef DL);
301+
302+
/// Set the data layout based on current triple and ABI.
303+
void resetDataLayout();
302304

303305
// Target features that are read-only and should not be disabled/enabled
304306
// by command line options. Such features are for emitting predefined

clang/lib/Basic/TargetInfo.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
156156
Float128Format = &llvm::APFloat::IEEEquad();
157157
Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
158158
MCountName = "mcount";
159-
UserLabelPrefix = "_";
159+
UserLabelPrefix = Triple.isOSBinFormatMachO() ? "_" : "";
160160
RegParmMax = 0;
161161
SSERegParmMax = 0;
162162
HasAlignMac68kSupport = false;
@@ -196,9 +196,10 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
196196
// Out of line virtual dtor for TargetInfo.
197197
TargetInfo::~TargetInfo() {}
198198

199-
void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
200-
DataLayoutString = DL.str();
201-
UserLabelPrefix = ULP;
199+
void TargetInfo::resetDataLayout(StringRef DL) { DataLayoutString = DL.str(); }
200+
201+
void TargetInfo::resetDataLayout() {
202+
DataLayoutString = Triple.computeDataLayout(getABI());
202203
}
203204

204205
bool

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
12121212
HasD128 = false;
12131213
}
12141214

1215-
setDataLayout();
1215+
resetDataLayout();
12161216

12171217
if (HasNoFP) {
12181218
FPU &= ~FPUMode;
@@ -1628,21 +1628,6 @@ AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple &Triple,
16281628
const TargetOptions &Opts)
16291629
: AArch64TargetInfo(Triple, Opts) {}
16301630

1631-
void AArch64leTargetInfo::setDataLayout() {
1632-
if (getTriple().isOSBinFormatMachO()) {
1633-
if(getTriple().isArch32Bit())
1634-
resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
1635-
"i128:128-n32:64-S128-Fn32",
1636-
"_");
1637-
else
1638-
resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"
1639-
"n32:64-S128-Fn32",
1640-
"_");
1641-
} else
1642-
resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
1643-
"i64:64-i128:128-n32:64-S128-Fn32");
1644-
}
1645-
16461631
void AArch64leTargetInfo::getTargetDefines(const LangOptions &Opts,
16471632
MacroBuilder &Builder) const {
16481633
Builder.defineMacro("__AARCH64EL__");
@@ -1661,12 +1646,6 @@ void AArch64beTargetInfo::getTargetDefines(const LangOptions &Opts,
16611646
AArch64TargetInfo::getTargetDefines(Opts, Builder);
16621647
}
16631648

1664-
void AArch64beTargetInfo::setDataLayout() {
1665-
assert(!getTriple().isOSBinFormatMachO());
1666-
resetDataLayout("E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
1667-
"i64:64-i128:128-n32:64-S128-Fn32");
1668-
}
1669-
16701649
WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
16711650
const TargetOptions &Opts)
16721651
: WindowsTargetInfo<AArch64leTargetInfo>(Triple, Opts), Triple(Triple) {
@@ -1685,15 +1664,6 @@ WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
16851664
IntPtrType = SignedLongLong;
16861665
}
16871666

1688-
void WindowsARM64TargetInfo::setDataLayout() {
1689-
resetDataLayout(Triple.isOSBinFormatMachO()
1690-
? "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:"
1691-
"128-n32:64-S128-Fn32"
1692-
: "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
1693-
"i64:64-i128:128-n32:64-S128-Fn32",
1694-
Triple.isOSBinFormatMachO() ? "_" : "");
1695-
}
1696-
16971667
TargetInfo::BuiltinVaListKind
16981668
WindowsARM64TargetInfo::getBuiltinVaListKind() const {
16991669
return TargetInfo::CharPtrBuiltinVaList;

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static const unsigned ARM64AddrSpaceMap[] = {
5454
};
5555

5656
class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
57-
virtual void setDataLayout() = 0;
5857
static const TargetInfo::GCCRegAlias GCCRegAliases[];
5958
static const char *const GCCRegNames[];
6059

@@ -274,9 +273,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
274273
AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
275274

276275
void getTargetDefines(const LangOptions &Opts,
277-
MacroBuilder &Builder) const override;
278-
private:
279-
void setDataLayout() override;
276+
MacroBuilder &Builder) const override;
280277
};
281278

282279
template <>
@@ -297,8 +294,6 @@ class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
297294
WindowsARM64TargetInfo(const llvm::Triple &Triple,
298295
const TargetOptions &Opts);
299296

300-
void setDataLayout() override;
301-
302297
BuiltinVaListKind getBuiltinVaListKind() const override;
303298

304299
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
@@ -332,9 +327,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
332327
AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
333328
void getTargetDefines(const LangOptions &Opts,
334329
MacroBuilder &Builder) const override;
335-
336-
private:
337-
void setDataLayout() override;
338330
};
339331

340332
void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts,

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ namespace targets {
2626
// If you edit the description strings, make sure you update
2727
// getPointerWidthV().
2828

29-
static const char *const DataLayoutStringR600 =
30-
"e-m:e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
31-
"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1";
32-
33-
static const char *const DataLayoutStringAMDGCN =
34-
"e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32"
35-
"-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-"
36-
"v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-"
37-
"v2048:2048-n32:64-S32-A5-G1-ni:7:8:9";
38-
3929
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
4030
llvm::AMDGPUAS::FLAT_ADDRESS, // Default
4131
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global
@@ -237,8 +227,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
237227
GPUFeatures(isAMDGCN(Triple) ?
238228
llvm::AMDGPU::getArchAttrAMDGCN(GPUKind) :
239229
llvm::AMDGPU::getArchAttrR600(GPUKind)) {
240-
resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN
241-
: DataLayoutStringR600);
230+
resetDataLayout();
242231

243232
setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
244233
!isAMDGCN(Triple));

clang/lib/Basic/Targets/ARC.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class LLVM_LIBRARY_VISIBILITY ARCTargetInfo : public TargetInfo {
3333
PtrDiffType = SignedInt;
3434
IntPtrType = SignedInt;
3535
UseZeroLengthBitfieldAlignment = true;
36-
resetDataLayout("e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-"
37-
"i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32");
36+
resetDataLayout();
3837
}
3938

4039
void getTargetDefines(const LangOptions &Opts,

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,12 @@ void ARMTargetInfo::setABIAAPCS() {
3939

4040
ZeroLengthBitfieldBoundary = 0;
4141

42-
// Thumb1 add sp, #imm requires the immediate value be multiple of 4,
43-
// so set preferred for small types to 32.
44-
if (T.isOSBinFormatMachO()) {
45-
resetDataLayout(BigEndian
46-
? "E-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
47-
: "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
48-
"_");
49-
} else if (T.isOSWindows()) {
50-
assert(!BigEndian && "Windows on ARM does not support big endian");
51-
resetDataLayout("e"
52-
"-m:w"
53-
"-p:32:32"
54-
"-Fi8"
55-
"-i64:64"
56-
"-v128:64:128"
57-
"-a:0:32"
58-
"-n32"
59-
"-S64");
60-
} else {
61-
resetDataLayout(BigEndian
62-
? "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
63-
: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
64-
}
42+
resetDataLayout();
6543

6644
// FIXME: Enumerated types are variable width in straight AAPCS.
6745
}
6846

6947
void ARMTargetInfo::setABIAPCS(bool IsAAPCS16) {
70-
const llvm::Triple &T = getTriple();
71-
7248
IsAAPCS = false;
7349

7450
if (IsAAPCS16)
@@ -89,20 +65,7 @@ void ARMTargetInfo::setABIAPCS(bool IsAAPCS16) {
8965
/// gcc.
9066
ZeroLengthBitfieldBoundary = 32;
9167

92-
if (T.isOSBinFormatMachO() && IsAAPCS16) {
93-
assert(!BigEndian && "AAPCS16 does not support big-endian");
94-
resetDataLayout("e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128", "_");
95-
} else if (T.isOSBinFormatMachO())
96-
resetDataLayout(
97-
BigEndian
98-
? "E-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
99-
: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32",
100-
"_");
101-
else
102-
resetDataLayout(
103-
BigEndian
104-
? "E-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
105-
: "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
68+
resetDataLayout();
10669

10770
// FIXME: Override "preferred align" for double and long long.
10871
}
@@ -1545,7 +1508,7 @@ CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple,
15451508
this->WCharType = TargetInfo::UnsignedShort;
15461509
TLSSupported = false;
15471510
DoubleAlign = LongLongAlign = 64;
1548-
resetDataLayout("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
1511+
resetDataLayout();
15491512
}
15501513

15511514
void CygwinARMTargetInfo::getTargetDefines(const LangOptions &Opts,

clang/lib/Basic/Targets/AVR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
5757
Int16Type = SignedInt;
5858
Char32Type = UnsignedLong;
5959
SigAtomicType = SignedChar;
60-
resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8");
60+
resetDataLayout();
6161
}
6262

6363
void getTargetDefines(const LangOptions &Opts,

clang/lib/Basic/Targets/BPF.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
3434
IntMaxType = SignedLong;
3535
Int64Type = SignedLong;
3636
RegParmMax = 5;
37-
if (Triple.getArch() == llvm::Triple::bpfeb) {
38-
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
39-
} else {
40-
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
41-
}
37+
resetDataLayout();
4238
MaxAtomicPromoteWidth = 64;
4339
MaxAtomicInlineWidth = 64;
4440
TLSSupported = false;

clang/lib/Basic/Targets/CSKY.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {
5252

5353
UseZeroLengthBitfieldAlignment = true;
5454
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
55-
resetDataLayout("e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-"
56-
"v64:32:32-v128:32:32-a:0:32-Fi32-n32");
57-
5855
setABI("abiv2");
56+
resetDataLayout();
5957
}
6058

6159
StringRef getABI() const override { return ABI; }

0 commit comments

Comments
 (0)