r264540 - [modules] When encoding SourceLocations in bitcode, rotate the 'is macro' flag
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 27 13:13:25 PDT 2016
Author: rsmith
Date: Sun Mar 27 15:13:24 2016
New Revision: 264540
URL: http://llvm.org/viewvc/llvm-project?rev=264540&view=rev
Log:
[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%.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=264540&r1=264539&r2=264540&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Sun Mar 27 15:13:24 2016
@@ -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);
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=264540&r1=264539&r2=264540&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Mar 27 15:13:24 2016
@@ -2341,9 +2341,9 @@ ASTReader::ReadControlBlock(ModuleFile &
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::Read
// 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::findNext
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::findPrep
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::findPrep
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;
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=264540&r1=264539&r2=264540&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Mar 27 15:13:24 2016
@@ -1912,7 +1912,7 @@ void ASTWriter::WriteSourceManagerBlock(
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(
} 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::WritePragmaDiagnosticMap
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(R
}
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) {
More information about the cfe-commits
mailing list