[modules] Store a local offset to DeclContext lexical and visible contents. Saves a few bytes for each primary DeclContext.

llvm-svn: 264377
This commit is contained in:
Richard Smith 2016-03-25 01:17:43 +00:00
parent 8c8fcb2585
commit e37e9f43b7
2 changed files with 18 additions and 9 deletions

View File

@ -53,6 +53,12 @@ namespace clang {
uint64_t GetCurrentCursorOffset();
uint64_t ReadLocalOffset(const RecordData &R, unsigned &I) {
uint64_t LocalOffset = R[I++];
assert(LocalOffset < Offset && "offset point after current record");
return LocalOffset ? Offset - LocalOffset : 0;
}
SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
return Reader.ReadSourceLocation(F, R, I);
}
@ -2189,8 +2195,8 @@ void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {
std::pair<uint64_t, uint64_t>
ASTDeclReader::VisitDeclContext(DeclContext *DC) {
uint64_t LexicalOffset = Record[Idx++];
uint64_t VisibleOffset = Record[Idx++];
uint64_t LexicalOffset = ReadLocalOffset(Record, Idx);
uint64_t VisibleOffset = ReadLocalOffset(Record, Idx);
return std::make_pair(LexicalOffset, VisibleOffset);
}
@ -2225,10 +2231,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
for (unsigned I = 0; I != N - 1; ++I)
MergeWith = ReadDecl(Record, Idx/*, MergeWith*/);
RedeclOffset = Record[Idx++];
// RedeclOffset is a delta relative to the start of this record.
if (RedeclOffset)
RedeclOffset = Offset - RedeclOffset;
RedeclOffset = ReadLocalOffset(Record, Idx);
} else {
// This declaration was not the first local declaration. Read the first
// local declaration now, to trigger the import of other redeclarations.

View File

@ -136,6 +136,12 @@ namespace clang {
void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
void AddLocalOffset(uint64_t LocalOffset) {
uint64_t Offset = Writer.Stream.GetCurrentBitNo();
assert(LocalOffset < Offset && "invalid offset");
Record.push_back(LocalOffset ? Offset - LocalOffset : 0);
}
/// Add an Objective-C type parameter list to the given record.
void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
// Empty type parameter list.
@ -1555,8 +1561,8 @@ void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
/// contexts.
void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
uint64_t VisibleOffset) {
Record.push_back(LexicalOffset);
Record.push_back(VisibleOffset);
AddLocalOffset(LexicalOffset);
AddLocalOffset(VisibleOffset);
}
const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
@ -1626,7 +1632,7 @@ void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
else {
auto Start = Writer.Stream.GetCurrentBitNo();
Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
Record.push_back(Writer.Stream.GetCurrentBitNo() - Start);
AddLocalOffset(Start);
}
} else {
Record.push_back(0);