Skip to content

Commit 875b652

Browse files
authored
[DataLayout] Move operator= to cpp file (NFC) (#102849)
`DataLayout` isn't exactly cheap to copy (448 bytes on a 64-bit host). Move `operator=` to cpp file to improve compilation time. Also move `operator==` closer to `operator=` and add a couple of FIXMEs.
1 parent f696489 commit 875b652

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ class DataLayout {
120120
bool BigEndian;
121121

122122
unsigned AllocaAddrSpace;
123-
MaybeAlign StackNaturalAlign;
124123
unsigned ProgramAddrSpace;
125124
unsigned DefaultGlobalsAddrSpace;
126125

126+
MaybeAlign StackNaturalAlign;
127127
MaybeAlign FunctionPtrAlign;
128128
FunctionPtrAlignType TheFunctionPtrAlignType;
129129

@@ -139,6 +139,7 @@ class DataLayout {
139139
};
140140
ManglingModeT ManglingMode;
141141

142+
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
142143
SmallVector<unsigned char, 8> LegalIntWidths;
143144

144145
/// Primitive type alignment data. This is sorted by type and bit
@@ -201,26 +202,7 @@ class DataLayout {
201202

202203
~DataLayout(); // Not virtual, do not subclass this class
203204

204-
DataLayout &operator=(const DataLayout &DL) {
205-
clear();
206-
StringRepresentation = DL.StringRepresentation;
207-
BigEndian = DL.isBigEndian();
208-
AllocaAddrSpace = DL.AllocaAddrSpace;
209-
StackNaturalAlign = DL.StackNaturalAlign;
210-
FunctionPtrAlign = DL.FunctionPtrAlign;
211-
TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType;
212-
ProgramAddrSpace = DL.ProgramAddrSpace;
213-
DefaultGlobalsAddrSpace = DL.DefaultGlobalsAddrSpace;
214-
ManglingMode = DL.ManglingMode;
215-
LegalIntWidths = DL.LegalIntWidths;
216-
IntAlignments = DL.IntAlignments;
217-
FloatAlignments = DL.FloatAlignments;
218-
VectorAlignments = DL.VectorAlignments;
219-
StructAlignment = DL.StructAlignment;
220-
Pointers = DL.Pointers;
221-
NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces;
222-
return *this;
223-
}
205+
DataLayout &operator=(const DataLayout &Other);
224206

225207
bool operator==(const DataLayout &Other) const;
226208
bool operator!=(const DataLayout &Other) const { return !(*this == Other); }

llvm/lib/IR/DataLayout.cpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,45 @@ void DataLayout::reset(StringRef Desc) {
220220
return report_fatal_error(std::move(Err));
221221
}
222222

223+
DataLayout &DataLayout::operator=(const DataLayout &Other) {
224+
clear();
225+
StringRepresentation = Other.StringRepresentation;
226+
BigEndian = Other.BigEndian;
227+
AllocaAddrSpace = Other.AllocaAddrSpace;
228+
ProgramAddrSpace = Other.ProgramAddrSpace;
229+
DefaultGlobalsAddrSpace = Other.DefaultGlobalsAddrSpace;
230+
StackNaturalAlign = Other.StackNaturalAlign;
231+
FunctionPtrAlign = Other.FunctionPtrAlign;
232+
TheFunctionPtrAlignType = Other.TheFunctionPtrAlignType;
233+
ManglingMode = Other.ManglingMode;
234+
LegalIntWidths = Other.LegalIntWidths;
235+
IntAlignments = Other.IntAlignments;
236+
FloatAlignments = Other.FloatAlignments;
237+
VectorAlignments = Other.VectorAlignments;
238+
StructAlignment = Other.StructAlignment;
239+
Pointers = Other.Pointers;
240+
NonIntegralAddressSpaces = Other.NonIntegralAddressSpaces;
241+
return *this;
242+
}
243+
244+
bool DataLayout::operator==(const DataLayout &Other) const {
245+
// NOTE: StringRepresentation might differ, it is not canonicalized.
246+
// FIXME: NonIntegralAddressSpaces isn't compared.
247+
return BigEndian == Other.BigEndian &&
248+
AllocaAddrSpace == Other.AllocaAddrSpace &&
249+
ProgramAddrSpace == Other.ProgramAddrSpace &&
250+
DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
251+
StackNaturalAlign == Other.StackNaturalAlign &&
252+
FunctionPtrAlign == Other.FunctionPtrAlign &&
253+
TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
254+
ManglingMode == Other.ManglingMode &&
255+
LegalIntWidths == Other.LegalIntWidths &&
256+
IntAlignments == Other.IntAlignments &&
257+
FloatAlignments == Other.FloatAlignments &&
258+
VectorAlignments == Other.VectorAlignments &&
259+
StructAlignment == Other.StructAlignment && Pointers == Other.Pointers;
260+
}
261+
223262
Expected<DataLayout> DataLayout::parse(StringRef LayoutDescription) {
224263
DataLayout Layout("");
225264
if (Error Err = Layout.parseSpecifier(LayoutDescription))
@@ -556,25 +595,6 @@ DataLayout::DataLayout(const Module *M) {
556595

557596
void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
558597

559-
bool DataLayout::operator==(const DataLayout &Other) const {
560-
bool Ret = BigEndian == Other.BigEndian &&
561-
AllocaAddrSpace == Other.AllocaAddrSpace &&
562-
StackNaturalAlign == Other.StackNaturalAlign &&
563-
ProgramAddrSpace == Other.ProgramAddrSpace &&
564-
DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
565-
FunctionPtrAlign == Other.FunctionPtrAlign &&
566-
TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
567-
ManglingMode == Other.ManglingMode &&
568-
LegalIntWidths == Other.LegalIntWidths &&
569-
IntAlignments == Other.IntAlignments &&
570-
FloatAlignments == Other.FloatAlignments &&
571-
VectorAlignments == Other.VectorAlignments &&
572-
StructAlignment == Other.StructAlignment &&
573-
Pointers == Other.Pointers;
574-
// Note: getStringRepresentation() might differs, it is not canonicalized
575-
return Ret;
576-
}
577-
578598
static SmallVectorImpl<LayoutAlignElem>::const_iterator
579599
findAlignmentLowerBound(const SmallVectorImpl<LayoutAlignElem> &Alignments,
580600
uint32_t BitWidth) {

0 commit comments

Comments
 (0)