Skip to content

Commit

Permalink
[clang][modules] NFCI: Avoid unnecessary serialization logic for non-…
Browse files Browse the repository at this point in the history
…affecting files

This patch delays some `ASTWriter` logic until after we've checked whether the source location entry we're serializing as an affecting file or not.

Depends on D137214.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D137216
  • Loading branch information
jansvoboda11 committed Nov 2, 2022
1 parent aa2b05f commit a13122c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clang/lib/Serialization/ASTWriter.cpp
Expand Up @@ -2047,7 +2047,6 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
// Record the offset of this source-location entry.
uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase;
assert((Offset >> 32) == 0 && "SLocEntry offset too large");
SLocEntryOffsets.push_back(Offset);

// Figure out which record code to use.
unsigned Code;
Expand All @@ -2062,8 +2061,6 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
Record.clear();
Record.push_back(Code);

// Starting offset of this entry within this module, so skip the dummy.
Record.push_back(getAdjustedOffset(SLoc->getOffset()) - 2);
if (SLoc->isFile()) {
const SrcMgr::FileInfo &File = SLoc->getFile();
const SrcMgr::ContentCache *Content = &File.getContentCache();
Expand All @@ -2073,6 +2070,9 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
// Do not emit files that were not listed as inputs.
continue;
}
SLocEntryOffsets.push_back(Offset);
// Starting offset of this entry within this module, so skip the dummy.
Record.push_back(getAdjustedOffset(SLoc->getOffset()) - 2);
AddSourceLocation(File.getIncludeLoc(), Record);
Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
Record.push_back(File.hasLineDirectives());
Expand Down Expand Up @@ -2133,6 +2133,9 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
} else {
// The source location entry is a macro expansion.
const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion();
SLocEntryOffsets.push_back(Offset);
// Starting offset of this entry within this module, so skip the dummy.
Record.push_back(getAdjustedOffset(SLoc->getOffset()) - 2);
LocSeq::State Seq;
AddSourceLocation(Expansion.getSpellingLoc(), Record, Seq);
AddSourceLocation(Expansion.getExpansionLocStart(), Record, Seq);
Expand Down

0 comments on commit a13122c

Please sign in to comment.