Skip to content

Commit f4e071d

Browse files
committed
avoid passing ReadStableFunctionMapNames around
1 parent d11f8f4 commit f4e071d

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

llvm/include/llvm/CGData/StableFunctionMapRecord.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,20 @@ struct StableFunctionMapRecord {
6565
/// entry when passed in.
6666
LLVM_ABI static void deserializeEntry(const unsigned char *Ptr,
6767
stable_hash Hash,
68-
StableFunctionMap *FunctionMap,
69-
bool ReadStableFunctionMapNames = true);
68+
StableFunctionMap *FunctionMap);
7069

7170
/// Serialize the stable function map to a raw_ostream.
7271
LLVM_ABI void serialize(raw_ostream &OS,
7372
std::vector<CGDataPatchItem> &PatchItems) const;
7473

7574
/// Deserialize the stable function map from a raw_ostream.
76-
LLVM_ABI void deserialize(const unsigned char *&Ptr,
77-
bool ReadStableFunctionMapNames = true);
75+
LLVM_ABI void deserialize(const unsigned char *&Ptr);
7876

7977
/// Lazily deserialize the stable function map from `Buffer` starting at
8078
/// `Offset`. The individial stable function entry would be read lazily from
8179
/// `Buffer` when the function map is accessed.
8280
LLVM_ABI void lazyDeserialize(std::shared_ptr<MemoryBuffer> Buffer,
83-
uint64_t Offset,
84-
bool ReadStableFunctionMapNames = true);
81+
uint64_t Offset);
8582

8683
/// Serialize the stable function map to a YAML stream.
8784
LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
@@ -106,9 +103,15 @@ struct StableFunctionMapRecord {
106103
serializeYAML(YOS);
107104
}
108105

106+
void setReadStableFunctionMapNames(bool Read) {
107+
assert(
108+
FunctionMap->empty() &&
109+
"Cannot change ReadStableFunctionMapNames after the map is populated");
110+
FunctionMap->ReadStableFunctionMapNames = Read;
111+
}
112+
109113
private:
110-
void deserialize(const unsigned char *&Ptr, bool ReadStableFunctionMapNames,
111-
bool Lazy);
114+
void deserialize(const unsigned char *&Ptr, bool Lazy);
112115
};
113116

114117
} // namespace llvm

llvm/lib/CGData/CodeGenDataReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ Error IndexedCodeGenDataReader::read() {
122122
const unsigned char *Ptr = Start + Header.StableFunctionMapOffset;
123123
if (Ptr >= End)
124124
return error(cgdata_error::eof);
125+
FunctionMapRecord.setReadStableFunctionMapNames(
126+
IndexedCodeGenDataReadFunctionMapNames);
125127
if (IndexedCodeGenDataLazyLoading)
126128
FunctionMapRecord.lazyDeserialize(SharedDataBuffer,
127-
Header.StableFunctionMapOffset,
128-
IndexedCodeGenDataReadFunctionMapNames);
129+
Header.StableFunctionMapOffset);
129130
else
130-
FunctionMapRecord.deserialize(Ptr,
131-
IndexedCodeGenDataReadFunctionMapNames);
131+
FunctionMapRecord.deserialize(Ptr);
132132
}
133133

134134
return success();

llvm/lib/CGData/StableFunctionMap.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ void StableFunctionMap::deserializeLazyLoadingEntry(
150150
std::call_once(Storage.LazyLoadFlag, [this, HashArg = Hash, &StorageArg = Storage]() {
151151
for (auto Offset : StorageArg.Offsets)
152152
StableFunctionMapRecord::deserializeEntry(
153-
reinterpret_cast<const unsigned char *>(Offset), HashArg, const_cast<StableFunctionMap *>(this),
154-
ReadStableFunctionMapNames);
153+
reinterpret_cast<const unsigned char *>(Offset), HashArg, const_cast<StableFunctionMap *>(this));
155154
});
156155
}
157156

llvm/lib/CGData/StableFunctionMapRecord.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,17 @@ void StableFunctionMapRecord::serialize(
142142
&IndexOperandHashesByteSize, 1);
143143
}
144144

145-
void StableFunctionMapRecord::deserializeEntry(
146-
const unsigned char *Ptr, stable_hash Hash, StableFunctionMap *FunctionMap,
147-
bool ReadStableFunctionMapNames) {
148-
assert(FunctionMap->ReadStableFunctionMapNames == ReadStableFunctionMapNames);
145+
void StableFunctionMapRecord::deserializeEntry(const unsigned char *Ptr,
146+
stable_hash Hash,
147+
StableFunctionMap *FunctionMap) {
149148
auto FunctionNameId =
150149
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
151-
if (ReadStableFunctionMapNames)
150+
if (FunctionMap->ReadStableFunctionMapNames)
152151
assert(FunctionMap->getNameForId(FunctionNameId) &&
153152
"FunctionNameId out of range");
154153
auto ModuleNameId =
155154
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
156-
if (ReadStableFunctionMapNames)
155+
if (FunctionMap->ReadStableFunctionMapNames)
157156
assert(FunctionMap->getNameForId(ModuleNameId) &&
158157
"ModuleNameId out of range");
159158
auto InstCount =
@@ -191,7 +190,6 @@ void StableFunctionMapRecord::deserializeEntry(
191190
}
192191

193192
void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
194-
bool ReadStableFunctionMapNames,
195193
bool Lazy) {
196194
// Assert that Ptr is 4-byte aligned
197195
assert(((uintptr_t)Ptr % 4) == 0);
@@ -204,8 +202,7 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
204202
const auto NamesByteSize =
205203
endian::readNext<uint64_t, endianness::little, unaligned>(Ptr);
206204
const auto NamesOffset = reinterpret_cast<uintptr_t>(Ptr);
207-
FunctionMap->ReadStableFunctionMapNames = ReadStableFunctionMapNames;
208-
if (ReadStableFunctionMapNames) {
205+
if (FunctionMap->ReadStableFunctionMapNames) {
209206
for (unsigned I = 0; I < NumNames; ++I) {
210207
StringRef Name(reinterpret_cast<const char *>(Ptr));
211208
Ptr += Name.size() + 1;
@@ -243,7 +240,7 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
243240
else
244241
deserializeEntry(
245242
reinterpret_cast<const unsigned char *>(FixedSizeFieldsOffset), Hash,
246-
FunctionMap.get(), ReadStableFunctionMapNames);
243+
FunctionMap.get());
247244
FixedSizeFieldsOffset += FixedSizeFieldsSizePerEntry;
248245
}
249246

@@ -256,17 +253,15 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
256253
reinterpret_cast<uintptr_t>(Ptr) + IndexOperandHashesByteSize);
257254
}
258255

259-
void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
260-
bool ReadStableFunctionMapNames) {
261-
deserialize(Ptr, ReadStableFunctionMapNames, /*Lazy=*/false);
256+
void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr) {
257+
deserialize(Ptr, /*Lazy=*/false);
262258
}
263259

264260
void StableFunctionMapRecord::lazyDeserialize(
265-
std::shared_ptr<MemoryBuffer> Buffer, uint64_t Offset,
266-
bool ReadStableFunctionMapNames) {
261+
std::shared_ptr<MemoryBuffer> Buffer, uint64_t Offset) {
267262
const auto *Ptr = reinterpret_cast<const unsigned char *>(
268263
reinterpret_cast<uintptr_t>(Buffer->getBufferStart()) + Offset);
269-
deserialize(Ptr, ReadStableFunctionMapNames, /*Lazy=*/true);
264+
deserialize(Ptr, /*Lazy=*/true);
270265
FunctionMap->Buffer = std::move(Buffer);
271266
}
272267

0 commit comments

Comments
 (0)