[modules] When encoding SourceLocations in bitcode, rotate the 'is macro' flag

bit from the top bit to the bottom bit, so that we don't need 6 VBR6 hunks for
each macro location. Reduces libstdc++ module size by about 1%.

llvm-svn: 264540
This commit is contained in:
Richard Smith
2016-03-27 20:13:24 +00:00
parent 8930aab886
commit b22a1d186f
3 changed files with 27 additions and 18 deletions

View File

@@ -1979,9 +1979,15 @@ public:
/// \brief Read the contents of a CXXCtorInitializer array.
CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
/// \brief Read a source location from raw form and return it in its
/// originating module file's source location space.
SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
}
/// \brief Read a source location from raw form.
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
return TranslateSourceLocation(ModuleFile, Loc);
}

View File

@@ -2341,9 +2341,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
ModuleKind ImportedKind = (ModuleKind)Record[Idx++];
// The import location will be the local one for now; we will adjust
// all import locations of module imports after the global source
// location info are setup.
// location info are setup, in ReadAST.
SourceLocation ImportLoc =
SourceLocation::getFromRawEncoding(Record[Idx++]);
ReadUntranslatedSourceLocation(Record[Idx++]);
off_t StoredSize = (off_t)Record[Idx++];
time_t StoredModTime = (time_t)Record[Idx++];
ASTFileSignature StoredSignature = Record[Idx++];
@@ -3601,11 +3601,12 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
// Set the import location.
F.DirectImportLoc = ImportLoc;
// FIXME: We assume that locations from PCH / preamble do not need
// any translation.
if (!M->ImportedBy)
F.ImportLoc = M->ImportLoc;
else
F.ImportLoc = ReadSourceLocation(*M->ImportedBy,
M->ImportLoc.getRawEncoding());
F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc);
}
if (!Context.getLangOpts().CPlusPlus ||
@@ -4982,7 +4983,6 @@ PreprocessedEntityID ASTReader::findNextPreprocessedEntity(
namespace {
template <unsigned PPEntityOffset::*PPLoc>
struct PPEntityComp {
const ASTReader &Reader;
ModuleFile &M;
@@ -5006,7 +5006,7 @@ struct PPEntityComp {
}
SourceLocation getLoc(const PPEntityOffset &PPE) const {
return Reader.ReadSourceLocation(M, PPE.*PPLoc);
return Reader.TranslateSourceLocation(M, PPE.getBegin());
}
};
@@ -5037,7 +5037,7 @@ PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc,
if (EndsAfter) {
PPI = std::upper_bound(pp_begin, pp_end, Loc,
PPEntityComp<&PPEntityOffset::Begin>(*this, M));
PPEntityComp(*this, M));
} else {
// Do a binary search manually instead of using std::lower_bound because
// The end locations of entities may be unordered (when a macro expansion
@@ -5047,8 +5047,8 @@ PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc,
Half = Count / 2;
PPI = First;
std::advance(PPI, Half);
if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End),
Loc)) {
if (SourceMgr.isBeforeInTranslationUnit(
TranslateSourceLocation(M, PPI->getEnd()), Loc)) {
First = PPI;
++First;
Count = Count - Half - 1;

View File

@@ -1912,7 +1912,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
Record.push_back(SLoc->getOffset() - 2);
if (SLoc->isFile()) {
const SrcMgr::FileInfo &File = SLoc->getFile();
Record.push_back(File.getIncludeLoc().getRawEncoding());
AddSourceLocation(File.getIncludeLoc(), Record);
Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
Record.push_back(File.hasLineDirectives());
@@ -1984,10 +1984,12 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
} else {
// The source location entry is a macro expansion.
const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion();
Record.push_back(Expansion.getSpellingLoc().getRawEncoding());
Record.push_back(Expansion.getExpansionLocStart().getRawEncoding());
Record.push_back(Expansion.isMacroArgExpansion() ? 0
: Expansion.getExpansionLocEnd().getRawEncoding());
AddSourceLocation(Expansion.getSpellingLoc(), Record);
AddSourceLocation(Expansion.getExpansionLocStart(), Record);
AddSourceLocation(Expansion.isMacroArgExpansion()
? SourceLocation()
: Expansion.getExpansionLocEnd(),
Record);
// Compute the token length for this macro expansion.
unsigned NextOffset = SourceMgr.getNextLocalOffset();
@@ -2669,7 +2671,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
if (point.Loc.isInvalid())
continue;
Record.push_back(point.Loc.getRawEncoding());
AddSourceLocation(point.Loc, Record);
unsigned &DiagStateID = DiagStateIDMap[point.State];
Record.push_back(DiagStateID);
@@ -4782,7 +4784,8 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
}
void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) {
Record.push_back(Loc.getRawEncoding());
uint32_t Raw = Loc.getRawEncoding();
Record.push_back((Raw << 1) | (Raw >> 31));
}
void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) {