-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DataLayout] Move operator=
to cpp file (NFC)
#102849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataLayout] Move operator=
to cpp file (NFC)
#102849
Conversation
@llvm/pr-subscribers-llvm-ir Author: Sergei Barannikov (s-barannikov) Changes
Full diff: https://github.com/llvm/llvm-project/pull/102849.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index afcb8bcb77f10a..8e6a8f62b3a048 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -120,10 +120,10 @@ class DataLayout {
bool BigEndian;
unsigned AllocaAddrSpace;
- MaybeAlign StackNaturalAlign;
unsigned ProgramAddrSpace;
unsigned DefaultGlobalsAddrSpace;
+ MaybeAlign StackNaturalAlign;
MaybeAlign FunctionPtrAlign;
FunctionPtrAlignType TheFunctionPtrAlignType;
@@ -139,6 +139,7 @@ class DataLayout {
};
ManglingModeT ManglingMode;
+ // FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
SmallVector<unsigned char, 8> LegalIntWidths;
/// Primitive type alignment data. This is sorted by type and bit
@@ -201,26 +202,7 @@ class DataLayout {
~DataLayout(); // Not virtual, do not subclass this class
- DataLayout &operator=(const DataLayout &DL) {
- clear();
- StringRepresentation = DL.StringRepresentation;
- BigEndian = DL.isBigEndian();
- AllocaAddrSpace = DL.AllocaAddrSpace;
- StackNaturalAlign = DL.StackNaturalAlign;
- FunctionPtrAlign = DL.FunctionPtrAlign;
- TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType;
- ProgramAddrSpace = DL.ProgramAddrSpace;
- DefaultGlobalsAddrSpace = DL.DefaultGlobalsAddrSpace;
- ManglingMode = DL.ManglingMode;
- LegalIntWidths = DL.LegalIntWidths;
- IntAlignments = DL.IntAlignments;
- FloatAlignments = DL.FloatAlignments;
- VectorAlignments = DL.VectorAlignments;
- StructAlignment = DL.StructAlignment;
- Pointers = DL.Pointers;
- NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces;
- return *this;
- }
+ DataLayout &operator=(const DataLayout &Other);
bool operator==(const DataLayout &Other) const;
bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index 5104cb86320be7..81479fb365e64f 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -220,6 +220,47 @@ void DataLayout::reset(StringRef Desc) {
return report_fatal_error(std::move(Err));
}
+DataLayout &DataLayout::operator=(const DataLayout &Other) {
+ clear();
+ StringRepresentation = Other.StringRepresentation;
+ BigEndian = Other.BigEndian;
+ AllocaAddrSpace = Other.AllocaAddrSpace;
+ ProgramAddrSpace = Other.ProgramAddrSpace;
+ DefaultGlobalsAddrSpace = Other.DefaultGlobalsAddrSpace;
+ StackNaturalAlign = Other.StackNaturalAlign;
+ FunctionPtrAlign = Other.FunctionPtrAlign;
+ TheFunctionPtrAlignType = Other.TheFunctionPtrAlignType;
+ ManglingMode = Other.ManglingMode;
+ LegalIntWidths = Other.LegalIntWidths;
+ IntAlignments = Other.IntAlignments;
+ FloatAlignments = Other.FloatAlignments;
+ VectorAlignments = Other.VectorAlignments;
+ StructAlignment = Other.StructAlignment;
+ Pointers = Other.Pointers;
+ NonIntegralAddressSpaces = Other.NonIntegralAddressSpaces;
+ return *this;
+}
+
+bool DataLayout::operator==(const DataLayout &Other) const {
+ // FIXME: NonIntegralAddressSpaces isn't compared.
+ bool Ret = BigEndian == Other.BigEndian &&
+ AllocaAddrSpace == Other.AllocaAddrSpace &&
+ ProgramAddrSpace == Other.ProgramAddrSpace &&
+ DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
+ StackNaturalAlign == Other.StackNaturalAlign &&
+ FunctionPtrAlign == Other.FunctionPtrAlign &&
+ TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
+ ManglingMode == Other.ManglingMode &&
+ LegalIntWidths == Other.LegalIntWidths &&
+ IntAlignments == Other.IntAlignments &&
+ FloatAlignments == Other.FloatAlignments &&
+ VectorAlignments == Other.VectorAlignments &&
+ StructAlignment == Other.StructAlignment &&
+ Pointers == Other.Pointers;
+ // Note: getStringRepresentation() might differs, it is not canonicalized
+ return Ret;
+}
+
Expected<DataLayout> DataLayout::parse(StringRef LayoutDescription) {
DataLayout Layout("");
if (Error Err = Layout.parseSpecifier(LayoutDescription))
@@ -556,25 +597,6 @@ DataLayout::DataLayout(const Module *M) {
void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
-bool DataLayout::operator==(const DataLayout &Other) const {
- bool Ret = BigEndian == Other.BigEndian &&
- AllocaAddrSpace == Other.AllocaAddrSpace &&
- StackNaturalAlign == Other.StackNaturalAlign &&
- ProgramAddrSpace == Other.ProgramAddrSpace &&
- DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
- FunctionPtrAlign == Other.FunctionPtrAlign &&
- TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
- ManglingMode == Other.ManglingMode &&
- LegalIntWidths == Other.LegalIntWidths &&
- IntAlignments == Other.IntAlignments &&
- FloatAlignments == Other.FloatAlignments &&
- VectorAlignments == Other.VectorAlignments &&
- StructAlignment == Other.StructAlignment &&
- Pointers == Other.Pointers;
- // Note: getStringRepresentation() might differs, it is not canonicalized
- return Ret;
-}
-
static SmallVectorImpl<LayoutAlignElem>::const_iterator
findAlignmentLowerBound(const SmallVectorImpl<LayoutAlignElem> &Alignments,
uint32_t BitWidth) {
|
2eaa263
to
d1fddc0
Compare
`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.
d1fddc0
to
43848bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
DataLayout
isn't exactly cheap to copy (448 bytes on a 64-bit host). Moveoperator=
to cpp file to improve compilation time. Also moveoperator==
closer tooperator=
and add a couple of FIXMEs.