[cfe-commits] r140208 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Sep 20 16:27:38 PDT 2011
Author: akirtzidis
Date: Tue Sep 20 18:27:38 2011
New Revision: 140208
URL: http://llvm.org/viewvc/llvm-project?rev=140208&view=rev
Log:
[PCH] Merge ASTReader::LoadPreprocessedEntity with ReadPreprocessedEntity
and don't store the ID for each preprocessed entity.
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=140208&r1=140207&r2=140208&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Sep 20 18:27:38 2011
@@ -1229,10 +1229,6 @@
/// \brief Reads the macro record located at the given offset.
void ReadMacroRecord(Module &F, uint64_t Offset);
-
- /// \brief Reads the preprocessed entity located at the current stream
- /// position.
- PreprocessedEntity *LoadPreprocessedEntity(Module &F);
/// \brief Determine the global preprocessed entity ID that corresponds to
/// the given local ID within the given module.
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=140208&r1=140207&r2=140208&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Sep 20 18:27:38 2011
@@ -1346,98 +1346,6 @@
return;
}
-PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) {
- unsigned Code = F.PreprocessorDetailCursor.ReadCode();
- switch (Code) {
- case llvm::bitc::END_BLOCK:
- return 0;
-
- case llvm::bitc::ENTER_SUBBLOCK:
- Error("unexpected subblock record in preprocessor detail block");
- return 0;
-
- case llvm::bitc::DEFINE_ABBREV:
- Error("unexpected abbrevation record in preprocessor detail block");
- return 0;
-
- default:
- break;
- }
-
- if (!PP.getPreprocessingRecord()) {
- Error("no preprocessing record");
- return 0;
- }
-
- // Read the record.
- PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
- const char *BlobStart = 0;
- unsigned BlobLen = 0;
- RecordData Record;
- PreprocessorDetailRecordTypes RecType =
- (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord(
- Code, Record, BlobStart, BlobLen);
- switch (RecType) {
- case PPD_MACRO_EXPANSION: {
- bool isBuiltin = Record[3];
- MacroExpansion *ME;
- if (isBuiltin) {
- ME = new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[4]),
- SourceRange(ReadSourceLocation(F, Record[1]),
- ReadSourceLocation(F, Record[2])));
- } else {
- PreprocessedEntityID
- GlobalID = getGlobalPreprocessedEntityID(F, Record[4]);
- ME = new (PPRec) MacroExpansion(
- cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)),
- SourceRange(ReadSourceLocation(F, Record[1]),
- ReadSourceLocation(F, Record[2])));
- }
- return ME;
- }
-
- case PPD_MACRO_DEFINITION: {
- PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]);
-
- // Decode the identifier info and then check again; if the macro is
- // still defined and associated with the identifier,
- IdentifierInfo *II = getLocalIdentifier(F, Record[3]);
- MacroDefinition *MD
- = new (PPRec) MacroDefinition(II,
- SourceRange(
- ReadSourceLocation(F, Record[1]),
- ReadSourceLocation(F, Record[2])));
-
- if (DeserializationListener)
- DeserializationListener->MacroDefinitionRead(GlobalID, MD);
-
- return MD;
- }
-
- case PPD_INCLUSION_DIRECTIVE: {
- const char *FullFileNameStart = BlobStart + Record[3];
- const FileEntry *File
- = PP.getFileManager().getFile(StringRef(FullFileNameStart,
- BlobLen - Record[3]));
-
- // FIXME: Stable encoding
- InclusionDirective::InclusionKind Kind
- = static_cast<InclusionDirective::InclusionKind>(Record[5]);
- InclusionDirective *ID
- = new (PPRec) InclusionDirective(PPRec, Kind,
- StringRef(BlobStart, Record[3]),
- Record[4],
- File,
- SourceRange(ReadSourceLocation(F, Record[1]),
- ReadSourceLocation(F, Record[2])));
- return ID;
- }
- }
-
- Error("invalid offset in preprocessor detail block");
- return 0;
-}
-
PreprocessedEntityID
ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) const {
ContinuousRangeMap<uint32_t, int, 2>::const_iterator
@@ -2869,6 +2777,7 @@
}
PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
+ PreprocessedEntityID PPID = Index+1;
GlobalPreprocessedEntityMapType::iterator
I = GlobalPreprocessedEntityMap.find(Index);
assert(I != GlobalPreprocessedEntityMap.end() &&
@@ -2879,7 +2788,99 @@
SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor);
M.PreprocessorDetailCursor.JumpToBit(
M.PreprocessedEntityOffsets[LocalIndex].BitOffset);
- return LoadPreprocessedEntity(M);
+
+ unsigned Code = M.PreprocessorDetailCursor.ReadCode();
+ switch (Code) {
+ case llvm::bitc::END_BLOCK:
+ return 0;
+
+ case llvm::bitc::ENTER_SUBBLOCK:
+ Error("unexpected subblock record in preprocessor detail block");
+ return 0;
+
+ case llvm::bitc::DEFINE_ABBREV:
+ Error("unexpected abbrevation record in preprocessor detail block");
+ return 0;
+
+ default:
+ break;
+ }
+
+ if (!PP.getPreprocessingRecord()) {
+ Error("no preprocessing record");
+ return 0;
+ }
+
+ // Read the record.
+ PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
+ const char *BlobStart = 0;
+ unsigned BlobLen = 0;
+ RecordData Record;
+ PreprocessorDetailRecordTypes RecType =
+ (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord(
+ Code, Record, BlobStart, BlobLen);
+ switch (RecType) {
+ case PPD_MACRO_EXPANSION: {
+ SourceRange Range(ReadSourceLocation(M, Record[0]),
+ ReadSourceLocation(M, Record[1]));
+ bool isBuiltin = Record[2];
+ IdentifierInfo *Name = 0;
+ MacroDefinition *Def = 0;
+ if (isBuiltin)
+ Name = getLocalIdentifier(M, Record[3]);
+ else {
+ PreprocessedEntityID
+ GlobalID = getGlobalPreprocessedEntityID(M, Record[3]);
+ Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1));
+ }
+
+ MacroExpansion *ME;
+ if (isBuiltin)
+ ME = new (PPRec) MacroExpansion(Name, Range);
+ else
+ ME = new (PPRec) MacroExpansion(Def, Range);
+
+ return ME;
+ }
+
+ case PPD_MACRO_DEFINITION: {
+ // Decode the identifier info and then check again; if the macro is
+ // still defined and associated with the identifier,
+ IdentifierInfo *II = getLocalIdentifier(M, Record[2]);
+ MacroDefinition *MD
+ = new (PPRec) MacroDefinition(II,
+ SourceRange(
+ ReadSourceLocation(M, Record[0]),
+ ReadSourceLocation(M, Record[1])));
+
+ if (DeserializationListener)
+ DeserializationListener->MacroDefinitionRead(PPID, MD);
+
+ return MD;
+ }
+
+ case PPD_INCLUSION_DIRECTIVE: {
+ const char *FullFileNameStart = BlobStart + Record[2];
+ const FileEntry *File
+ = PP.getFileManager().getFile(StringRef(FullFileNameStart,
+ BlobLen - Record[2]));
+
+ // FIXME: Stable encoding
+ InclusionDirective::InclusionKind Kind
+ = static_cast<InclusionDirective::InclusionKind>(Record[4]);
+ InclusionDirective *ID
+ = new (PPRec) InclusionDirective(PPRec, Kind,
+ StringRef(BlobStart, Record[2]),
+ Record[3],
+ File,
+ SourceRange(ReadSourceLocation(M, Record[0]),
+ ReadSourceLocation(M, Record[1])));
+ return ID;
+ }
+ }
+
+ Error("invalid offset in preprocessor detail block");
+ return 0;
}
/// \brief \arg SLocMapI points at a chunk of a module that contains no
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=140208&r1=140207&r2=140208&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Sep 20 18:27:38 2011
@@ -1727,7 +1727,6 @@
{
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length
@@ -1755,7 +1754,6 @@
// Record this macro definition's ID.
MacroDefinitions[MD] = NextPreprocessorEntityID;
- Record.push_back(NextPreprocessorEntityID);
AddSourceLocation(MD->getSourceRange().getBegin(), Record);
AddSourceLocation(MD->getSourceRange().getEnd(), Record);
AddIdentifierRef(MD->getName(), Record);
@@ -1764,7 +1762,6 @@
}
if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) {
- Record.push_back(NextPreprocessorEntityID);
AddSourceLocation(ME->getSourceRange().getBegin(), Record);
AddSourceLocation(ME->getSourceRange().getEnd(), Record);
Record.push_back(ME->isBuiltinMacro());
@@ -1778,7 +1775,6 @@
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) {
Record.push_back(PPD_INCLUSION_DIRECTIVE);
- Record.push_back(NextPreprocessorEntityID);
AddSourceLocation(ID->getSourceRange().getBegin(), Record);
AddSourceLocation(ID->getSourceRange().getEnd(), Record);
Record.push_back(ID->getFileName().size());
More information about the cfe-commits
mailing list