Implement the local -> global remapping for macro definition IDs in

the detailed preprocessing record. Tested with the standard "gaps" method.

llvm-svn: 136882
This commit is contained in:
Douglas Gregor 2011-08-04 16:36:56 +00:00
parent 583b1e12f8
commit a863b4b4e3
4 changed files with 46 additions and 11 deletions

View File

@ -125,6 +125,9 @@ namespace clang {
/// \brief An ID number that refers to a macro in an AST file. /// \brief An ID number that refers to a macro in an AST file.
typedef uint32_t MacroID; typedef uint32_t MacroID;
/// \brief The number of predefined macro IDs.
const unsigned int NUM_PREDEF_MACRO_IDS = 1;
/// \brief An ID number that refers to an ObjC selctor in an AST file. /// \brief An ID number that refers to an ObjC selctor in an AST file.
typedef uint32_t SelectorID; typedef uint32_t SelectorID;

View File

@ -301,6 +301,9 @@ public:
/// module. /// module.
serialization::MacroID BaseMacroDefinitionID; serialization::MacroID BaseMacroDefinitionID;
/// \brief Remapping table for macro definition IDs in this module.
ContinuousRangeMap<uint32_t, int, 2> MacroDefinitionRemap;
// === Header search information === // === Header search information ===
/// \brief The number of local HeaderFileInfo structures. /// \brief The number of local HeaderFileInfo structures.

View File

@ -1875,8 +1875,15 @@ const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) {
} }
MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) {
// FIXME: Local-to-global mapping if (LocalID < NUM_PREDEF_MACRO_IDS)
return LocalID; return LocalID;
ContinuousRangeMap<uint32_t, int, 2>::iterator I
= M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS);
assert(I != M.MacroDefinitionRemap.end() &&
"Invalid index into macro definition ID remap");
return LocalID + I->second;
} }
/// \brief If we are loading a relocatable PCH file, and the filename is /// \brief If we are loading a relocatable PCH file, and the filename is
@ -2315,6 +2322,8 @@ ASTReader::ReadASTBlock(Module &F) {
ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder ContinuousRangeMap<uint32_t, int, 2>::Builder
IdentifierRemap(F.IdentifierRemap); IdentifierRemap(F.IdentifierRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder
MacroDefinitionRemap(F.MacroDefinitionRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder ContinuousRangeMap<uint32_t, int, 2>::Builder
SelectorRemap(F.SelectorRemap); SelectorRemap(F.SelectorRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap);
@ -2347,7 +2356,9 @@ ASTReader::ReadASTBlock(Module &F) {
std::make_pair(IdentifierIDOffset, std::make_pair(IdentifierIDOffset,
OM->BaseIdentifierID - IdentifierIDOffset)); OM->BaseIdentifierID - IdentifierIDOffset));
(void)PreprocessedEntityIDOffset; (void)PreprocessedEntityIDOffset;
(void)MacroDefinitionIDOffset; MacroDefinitionRemap.insert(
std::make_pair(MacroDefinitionIDOffset,
OM->BaseMacroDefinitionID - MacroDefinitionIDOffset));
SelectorRemap.insert(std::make_pair(SelectorIDOffset, SelectorRemap.insert(std::make_pair(SelectorIDOffset,
OM->BaseSelectorID - SelectorIDOffset)); OM->BaseSelectorID - SelectorIDOffset));
DeclRemap.insert(std::make_pair(DeclIDOffset, DeclRemap.insert(std::make_pair(DeclIDOffset,
@ -2475,7 +2486,8 @@ ASTReader::ReadASTBlock(Module &F) {
F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; F.MacroDefinitionOffsets = (const uint32_t *)BlobStart;
F.NumPreallocatedPreprocessingEntities = Record[0]; F.NumPreallocatedPreprocessingEntities = Record[0];
F.LocalNumMacroDefinitions = Record[1]; F.LocalNumMacroDefinitions = Record[1];
unsigned LocalBaseMacroID = Record[2];
// Introduce the global -> local mapping for preprocessed entities within // Introduce the global -> local mapping for preprocessed entities within
// this AST file. // this AST file.
unsigned StartingID; unsigned StartingID;
@ -2492,17 +2504,27 @@ ASTReader::ReadASTBlock(Module &F) {
// a particular allocation strategy in the preprocessing record. // a particular allocation strategy in the preprocessing record.
StartingID = getTotalNumPreprocessedEntities(); StartingID = getTotalNumPreprocessedEntities();
} }
GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F));
F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); F.BaseMacroDefinitionID = getTotalNumMacroDefinitions();
F.BasePreprocessedEntityID = StartingID; F.BasePreprocessedEntityID = StartingID;
// Introduce the global -> local mapping for macro definitions within if (F.LocalNumMacroDefinitions > 0) {
// this AST file. // Introduce the global -> local mapping for macro definitions within
GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); // this module.
GlobalMacroDefinitionMap.insert( GlobalMacroDefinitionMap.insert(
std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); std::make_pair(getTotalNumMacroDefinitions() + 1, &F));
MacroDefinitionsLoaded.resize(
// Introduce the local -> global mapping for macro definitions within
// this module.
F.MacroDefinitionRemap.insert(
std::make_pair(LocalBaseMacroID,
F.BaseMacroDefinitionID - LocalBaseMacroID));
MacroDefinitionsLoaded.resize(
MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions);
}
break; break;
} }
@ -5589,6 +5611,11 @@ void Module::dump() {
llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
<< " Number of types: " << LocalNumTypes << '\n'; << " Number of types: " << LocalNumTypes << '\n';
dumpLocalRemap("Type index map", TypeRemap); dumpLocalRemap("Type index map", TypeRemap);
llvm::errs() << " Base macro definition ID: " << BaseMacroDefinitionID
<< '\n'
<< " Number of macro definitions: " << LocalNumMacroDefinitions
<< '\n';
dumpLocalRemap("Macro definition ID map", MacroDefinitionRemap);
llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
<< " Number of decls: " << LocalNumDecls << '\n'; << " Number of decls: " << LocalNumDecls << '\n';
dumpLocalRemap("Decl ID map", DeclRemap); dumpLocalRemap("Decl ID map", DeclRemap);

View File

@ -1875,6 +1875,7 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first macro def
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
@ -1882,6 +1883,7 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
Record.push_back(MACRO_DEFINITION_OFFSETS); Record.push_back(MACRO_DEFINITION_OFFSETS);
Record.push_back(NumPreprocessingRecords); Record.push_back(NumPreprocessingRecords);
Record.push_back(MacroDefinitionOffsets.size()); Record.push_back(MacroDefinitionOffsets.size());
Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS);
Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record,
data(MacroDefinitionOffsets)); data(MacroDefinitionOffsets));
} }
@ -2748,7 +2750,7 @@ ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID),
FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID),
FirstMacroID(1), NextMacroID(FirstMacroID), FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID),
CollectedStmts(&StmtsToEmit), CollectedStmts(&StmtsToEmit),
NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
NumVisibleDeclContexts(0), NumVisibleDeclContexts(0),