Skip to content

Commit 61e8961

Browse files
committed
[clang][modules] Remove preloaded SLocEntries from PCM files
This commit removes the list of SLocEntry offsets to preload eagerly from PCM files. Commit introducing this functionality (258ae54) doesn't clarify why this would be more performant than the lazy approach used regularly. Currently, the only SLocEntry the reader is supposed to preload is the predefines buffer, but in my experience, it's not actually referenced in most modules, so the time spent deserializing its SLocEntry is wasted. This is especially noticeable in the dependency scanner, where this change brings 4.56% speedup on my benchmark.
1 parent c03d184 commit 61e8961

File tree

4 files changed

+2
-42
lines changed

4 files changed

+2
-42
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const unsigned VERSION_MAJOR = 29;
5151
/// for the previous version could still support reading the new
5252
/// version by ignoring new kinds of subblocks), this number
5353
/// should be increased.
54-
const unsigned VERSION_MINOR = 0;
54+
const unsigned VERSION_MINOR = 1;
5555

5656
/// An ID number that refers to an identifier in an AST file.
5757
///
@@ -524,13 +524,7 @@ enum ASTRecordTypes {
524524
/// of source-location information.
525525
SOURCE_LOCATION_OFFSETS = 14,
526526

527-
/// Record code for the set of source location entries
528-
/// that need to be preloaded by the AST reader.
529-
///
530-
/// This set contains the source location entry for the
531-
/// predefines buffer and for any file entries that need to be
532-
/// preloaded.
533-
SOURCE_LOCATION_PRELOADS = 15,
527+
// ID 15 used to be for source location entry preloads.
534528

535529
/// Record code for the set of ext_vector type names.
536530
EXT_VECTOR_DECLS = 16,

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,6 @@ class ModuleFile {
292292
/// AST file.
293293
const uint32_t *SLocEntryOffsets = nullptr;
294294

295-
/// SLocEntries that we're going to preload.
296-
SmallVector<uint64_t, 4> PreloadSLocEntries;
297-
298295
/// Remapping table for source locations in this module.
299296
ContinuousRangeMap<SourceLocation::UIntTy, SourceLocation::IntTy, 2>
300297
SLocRemap;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,6 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
32263226
case SOURCE_LOCATION_OFFSETS:
32273227
case MODULE_OFFSET_MAP:
32283228
case SOURCE_MANAGER_LINE_TABLE:
3229-
case SOURCE_LOCATION_PRELOADS:
32303229
case PPD_ENTITIES_OFFSETS:
32313230
case HEADER_SEARCH_TABLE:
32323231
case IMPORTED_MODULES:
@@ -3576,18 +3575,6 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
35763575
ParseLineTable(F, Record);
35773576
break;
35783577

3579-
case SOURCE_LOCATION_PRELOADS: {
3580-
// Need to transform from the local view (1-based IDs) to the global view,
3581-
// which is based off F.SLocEntryBaseID.
3582-
if (!F.PreloadSLocEntries.empty())
3583-
return llvm::createStringError(
3584-
std::errc::illegal_byte_sequence,
3585-
"Multiple SOURCE_LOCATION_PRELOADS records in AST file");
3586-
3587-
F.PreloadSLocEntries.swap(Record);
3588-
break;
3589-
}
3590-
35913578
case EXT_VECTOR_DECLS:
35923579
for (unsigned I = 0, N = Record.size(); I != N; ++I)
35933580
ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I]));
@@ -4417,16 +4404,6 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, ModuleKind Type,
44174404
for (ImportedModule &M : Loaded) {
44184405
ModuleFile &F = *M.Mod;
44194406

4420-
// Preload SLocEntries.
4421-
for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) {
4422-
int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID;
4423-
// Load it through the SourceManager and don't call ReadSLocEntry()
4424-
// directly because the entry may have already been loaded in which case
4425-
// calling ReadSLocEntry() directly would trigger an assertion in
4426-
// SourceManager.
4427-
SourceMgr.getLoadedSLocEntryByID(Index);
4428-
}
4429-
44304407
// Map the original source file ID into the ID space of the current
44314408
// compilation.
44324409
if (F.OriginalSourceFileID.isValid())

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ void ASTWriter::WriteBlockInfoBlock() {
838838
RECORD(METHOD_POOL);
839839
RECORD(PP_COUNTER_VALUE);
840840
RECORD(SOURCE_LOCATION_OFFSETS);
841-
RECORD(SOURCE_LOCATION_PRELOADS);
842841
RECORD(EXT_VECTOR_DECLS);
843842
RECORD(UNUSED_FILESCOPED_DECLS);
844843
RECORD(PPD_ENTITIES_OFFSETS);
@@ -2137,7 +2136,6 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
21372136
// entry, which is always the same dummy entry.
21382137
std::vector<uint32_t> SLocEntryOffsets;
21392138
uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo();
2140-
RecordData PreloadSLocs;
21412139
SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
21422140
for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
21432141
I != N; ++I) {
@@ -2213,9 +2211,6 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
22132211
Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
22142212
StringRef(Name.data(), Name.size() + 1));
22152213
EmitBlob = true;
2216-
2217-
if (Name == "<built-in>")
2218-
PreloadSLocs.push_back(SLocEntryOffsets.size());
22192214
}
22202215

22212216
if (EmitBlob) {
@@ -2277,9 +2272,6 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
22772272
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
22782273
bytes(SLocEntryOffsets));
22792274
}
2280-
// Write the source location entry preloads array, telling the AST
2281-
// reader which source locations entries it should load eagerly.
2282-
Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs);
22832275

22842276
// Write the line table. It depends on remapping working, so it must come
22852277
// after the source location offsets.

0 commit comments

Comments
 (0)