summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-03-25 01:17:43 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-03-25 01:17:43 +0000
commite37e9f43b73bfd67a90d3b4d0719d25f65007e9c (patch)
treed684bbc658ce9e7c76259073ade545f4e80b7258
parent8c8fcb2585b45dec7091fc9f3617dd8ef2bc4ac4 (diff)
downloadbcm5719-llvm-e37e9f43b73bfd67a90d3b4d0719d25f65007e9c.tar.gz
bcm5719-llvm-e37e9f43b73bfd67a90d3b4d0719d25f65007e9c.zip
[modules] Store a local offset to DeclContext lexical and visible contents. Saves a few bytes for each primary DeclContext.
llvm-svn: 264377
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp15
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp12
2 files changed, 18 insertions, 9 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 573a13aee2d..abfee00cf3a 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -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.
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index e22a94df2f3..752373646e6 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -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);
OpenPOWER on IntegriCloud