Introduce local -> global selector ID mapping into the AST

reader. Tested with the usual "gaps" method.

llvm-svn: 136839
This commit is contained in:
Douglas Gregor 2011-08-03 23:28:44 +00:00
parent 41dfb50c22
commit 8f364fbacc
5 changed files with 45 additions and 16 deletions

View File

@ -128,6 +128,9 @@ namespace clang {
/// \brief An ID number that refers to an ObjC selctor in an AST file.
typedef uint32_t SelectorID;
/// \brief The number of predefined selector IDs.
const unsigned int NUM_PREDEF_SELECTOR_IDS = 1;
/// \brief An ID number that refers to a set of CXXBaseSpecifiers in an
/// AST file.
typedef uint32_t CXXBaseSpecifiersID;

View File

@ -255,7 +255,7 @@ public:
/// \brief Base identifier ID for identifiers local to this module.
serialization::IdentID BaseIdentifierID;
/// \brief Remapping table for declaration IDs in this module.
/// \brief Remapping table for identifier IDs in this module.
ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
/// \brief Actual data for the on-disk hash table of identifiers.
@ -335,6 +335,9 @@ public:
/// \brief Base selector ID for selectors local to this module.
serialization::SelectorID BaseSelectorID;
/// \brief Remapping table for selector IDs in this module.
ContinuousRangeMap<uint32_t, int, 2> SelectorRemap;
/// \brief A pointer to the character data that comprises the selector table
///
/// The SelectorOffsets table refers into this memory.

View File

@ -2234,17 +2234,27 @@ ASTReader::ReadASTBlock(Module &F) {
LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I]));
break;
case SELECTOR_OFFSETS:
case SELECTOR_OFFSETS: {
F.SelectorOffsets = (const uint32_t *)BlobStart;
F.LocalNumSelectors = Record[0];
unsigned LocalBaseSelectorID = Record[1];
F.BaseSelectorID = getTotalNumSelectors();
// Introduce the global -> local mapping for identifiers within this AST
// file
GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors() + 1, &F));
SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
break;
if (F.LocalNumSelectors > 0) {
// Introduce the global -> local mapping for selectors within this
// module.
GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F));
// Introduce the local -> global mapping for selectors within this
// module.
F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID,
F.BaseSelectorID - LocalBaseSelectorID));
SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
}
break;
}
case METHOD_POOL:
F.SelectorLookupTableData = (const unsigned char *)BlobStart;
if (Record[0])
@ -2305,6 +2315,8 @@ ASTReader::ReadASTBlock(Module &F) {
ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder
IdentifierRemap(F.IdentifierRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder
SelectorRemap(F.SelectorRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap);
@ -2337,7 +2349,8 @@ ASTReader::ReadASTBlock(Module &F) {
OM->BaseIdentifierID - IdentifierIDOffset));
(void)PreprocessedEntityIDOffset;
(void)MacroDefinitionIDOffset;
(void)SelectorIDOffset;
SelectorRemap.insert(std::make_pair(SelectorIDOffset,
OM->BaseSelectorID - SelectorIDOffset));
DeclRemap.insert(std::make_pair(DeclIDOffset,
OM->BaseDeclID - DeclIDOffset));
@ -4873,7 +4886,7 @@ Selector ASTReader::DecodeSelector(serialization::SelectorID ID) {
assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
Module &M = *I->second;
ASTSelectorLookupTrait Trait(*this, M);
unsigned Idx = ID - 1 - M.BaseSelectorID;
unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS;
SelectorsLoaded[ID - 1] =
Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0);
if (DeserializationListener)
@ -4892,10 +4905,17 @@ uint32_t ASTReader::GetNumExternalSelectors() {
return getTotalNumSelectors() + 1;
}
serialization::SelectorID
ASTReader::getGlobalSelectorID(Module &F, unsigned LocalID) const {
// FIXME: Perform local -> global remapping
return LocalID;
serialization::SelectorID
ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const {
if (LocalID < NUM_PREDEF_SELECTOR_IDS)
return LocalID;
ContinuousRangeMap<uint32_t, int, 2>::iterator I
= M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS);
assert(I != M.SelectorRemap.end()
&& "Invalid index into identifier index remap");
return LocalID + I->second;
}
DeclarationName

View File

@ -1407,7 +1407,8 @@ ASTReader::DeclCursorForID(DeclID ID) {
GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Module *M = I->second;
return RecordLocation(M, M->DeclOffsets[ID - M->BaseDeclID - 1]);
return RecordLocation(M,
M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
}
ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {

View File

@ -2219,6 +2219,7 @@ void ASTWriter::WriteSelectors(Sema &SemaRef) {
Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
@ -2226,6 +2227,7 @@ void ASTWriter::WriteSelectors(Sema &SemaRef) {
Record.clear();
Record.push_back(SELECTOR_OFFSETS);
Record.push_back(SelectorOffsets.size());
Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS);
Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record,
data(SelectorOffsets));
}
@ -2745,8 +2747,8 @@ ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID),
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID),
FirstSelectorID(1),
NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID),
FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID),
FirstMacroID(1), NextMacroID(FirstMacroID),
CollectedStmts(&StmtsToEmit),
NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
NumVisibleDeclContexts(0),