Skip to content

Commit a9bb740

Browse files
committed
[DataLayout] Remove clear and reset methods (NFC)
`clear` was never necessary as it is always called on a fresh instance of the class or just before freeing an instance's memory. `reset` is effectively the same as the constructor.
1 parent 75c7bca commit a9bb740

File tree

3 files changed

+11
-38
lines changed

3 files changed

+11
-38
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,10 @@ class DataLayout {
185185
/// if the string is malformed.
186186
Error parseSpecifier(StringRef Desc);
187187

188-
// Free all internal data structures.
189-
void clear();
190-
191188
public:
192-
/// Constructs a DataLayout from a specification string. See reset().
193-
explicit DataLayout(StringRef LayoutDescription) {
194-
reset(LayoutDescription);
195-
}
189+
/// Constructs a DataLayout from a specification string.
190+
/// WARNING: Aborts execution if the string is malformed. Use parse() instead.
191+
explicit DataLayout(StringRef LayoutString);
196192

197193
DataLayout(const DataLayout &DL) { *this = DL; }
198194

@@ -203,9 +199,6 @@ class DataLayout {
203199
bool operator==(const DataLayout &Other) const;
204200
bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
205201

206-
/// Parse a data layout string (with fallback to default values).
207-
void reset(StringRef LayoutDescription);
208-
209202
/// Parse a data layout string and return the layout. Return an error
210203
/// description on failure.
211204
static Expected<DataLayout> parse(StringRef LayoutDescription);

llvm/lib/IR/DataLayout.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -191,36 +191,30 @@ static const std::pair<AlignTypeEnum, LayoutAlignElem> DefaultAlignments[] = {
191191
{VECTOR_ALIGN, {128, Align(16), Align(16)}}, // v16i8, v8i16, v4i32, ...
192192
};
193193

194-
void DataLayout::reset(StringRef Desc) {
195-
clear();
196-
197-
LayoutMap = nullptr;
194+
DataLayout::DataLayout(StringRef LayoutString) {
198195
BigEndian = false;
199196
AllocaAddrSpace = 0;
200-
StackNaturalAlign.reset();
201197
ProgramAddrSpace = 0;
202198
DefaultGlobalsAddrSpace = 0;
203-
FunctionPtrAlign.reset();
204199
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
205200
ManglingMode = MM_None;
206-
NonIntegralAddressSpaces.clear();
207201
StructAlignment = LayoutAlignElem::get(Align(1), Align(8), 0);
208202

209203
// Default alignments
210204
for (const auto &[Kind, Layout] : DefaultAlignments) {
211205
if (Error Err = setAlignment(Kind, Layout.ABIAlign, Layout.PrefAlign,
212206
Layout.TypeBitWidth))
213-
return report_fatal_error(std::move(Err));
207+
report_fatal_error(std::move(Err));
214208
}
215209
if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64))
216-
return report_fatal_error(std::move(Err));
210+
report_fatal_error(std::move(Err));
217211

218-
if (Error Err = parseSpecifier(Desc))
219-
return report_fatal_error(std::move(Err));
212+
if (Error Err = parseSpecifier(LayoutString))
213+
report_fatal_error(std::move(Err));
220214
}
221215

222216
DataLayout &DataLayout::operator=(const DataLayout &Other) {
223-
clear();
217+
// Copy everything except for LayoutMap, which will be recomputed on demand.
224218
StringRepresentation = Other.StringRepresentation;
225219
BigEndian = Other.BigEndian;
226220
AllocaAddrSpace = Other.AllocaAddrSpace;
@@ -716,19 +710,7 @@ class StructLayoutMap {
716710

717711
} // end anonymous namespace
718712

719-
void DataLayout::clear() {
720-
LegalIntWidths.clear();
721-
IntAlignments.clear();
722-
FloatAlignments.clear();
723-
VectorAlignments.clear();
724-
Pointers.clear();
725-
delete static_cast<StructLayoutMap *>(LayoutMap);
726-
LayoutMap = nullptr;
727-
}
728-
729-
DataLayout::~DataLayout() {
730-
clear();
731-
}
713+
DataLayout::~DataLayout() { delete static_cast<StructLayoutMap *>(LayoutMap); }
732714

733715
const StructLayout *DataLayout::getStructLayout(StructType *Ty) const {
734716
if (!LayoutMap)

llvm/lib/IR/Module.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
388388
setModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
389389
}
390390

391-
void Module::setDataLayout(StringRef Desc) {
392-
DL.reset(Desc);
393-
}
391+
void Module::setDataLayout(StringRef Desc) { DL = DataLayout(Desc); }
394392

395393
void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
396394

0 commit comments

Comments
 (0)