r235420 - [modules] Move list of exported module macros from IdentifierInfo lookup table to separate storage, adjacent to the macro directive history.
Jay Foad
jay.foad at gmail.com
Wed Apr 22 07:17:11 PDT 2015
On 21 April 2015 at 22:46, Richard Smith <richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Tue Apr 21 16:46:32 2015
> New Revision: 235420
>
> URL: http://llvm.org/viewvc/llvm-project?rev=235420&view=rev
> Log:
> [modules] Move list of exported module macros from IdentifierInfo lookup table to separate storage, adjacent to the macro directive history.
>
> This is substantially simpler, provides better space usage accounting in bcanalyzer,
> and gives a more compact representation. No functionality change intended.
>
> Modified:
> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> cfe/trunk/include/clang/Serialization/ASTReader.h
> cfe/trunk/lib/Serialization/ASTReader.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=235420&r1=235419&r2=235420&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Apr 21 16:46:32 2015
> @@ -777,8 +777,6 @@ IdentifierInfo *ASTIdentifierLookupTrait
> Bits >>= 1;
> bool ExtensionToken = Bits & 0x01;
> Bits >>= 1;
> - bool hasSubmoduleMacros = Bits & 0x01;
> - Bits >>= 1;
> bool hadMacroDefinition = Bits & 0x01;
> Bits >>= 1;
>
> @@ -820,49 +818,8 @@ IdentifierInfo *ASTIdentifierLookupTrait
> uint32_t MacroDirectivesOffset =
> endian::readNext<uint32_t, little, unaligned>(d);
> DataLen -= 4;
> - SmallVector<uint32_t, 8> LocalMacroIDs;
> - if (hasSubmoduleMacros) {
> - while (true) {
> - uint32_t LocalMacroID =
> - endian::readNext<uint32_t, little, unaligned>(d);
> - DataLen -= 4;
> - if (LocalMacroID == (uint32_t)-1) break;
> - LocalMacroIDs.push_back(LocalMacroID);
> - }
> - }
> -
> - if (F.Kind == MK_ImplicitModule || F.Kind == MK_ExplicitModule) {
> - // Macro definitions are stored from newest to oldest, so reverse them
> - // before registering them.
> - llvm::SmallVector<unsigned, 8> MacroSizes;
> - for (SmallVectorImpl<uint32_t>::iterator
> - I = LocalMacroIDs.begin(), E = LocalMacroIDs.end(); I != E; /**/) {
> - unsigned Size = 1;
> -
> - static const uint32_t HasOverridesFlag = 0x80000000U;
> - if (I + 1 != E && (I[1] & HasOverridesFlag))
> - Size += 1 + (I[1] & ~HasOverridesFlag);
>
> - MacroSizes.push_back(Size);
> - I += Size;
> - }
> -
> - SmallVectorImpl<uint32_t>::iterator I = LocalMacroIDs.end();
> - for (SmallVectorImpl<unsigned>::reverse_iterator SI = MacroSizes.rbegin(),
> - SE = MacroSizes.rend();
> - SI != SE; ++SI) {
> - I -= *SI;
> -
> - uint32_t LocalMacroID = *I;
> - ArrayRef<uint32_t> Overrides;
> - if (*SI != 1)
> - Overrides = llvm::makeArrayRef(&I[2], *SI - 2);
> - Reader.addPendingMacroFromModule(II, &F, LocalMacroID, Overrides);
> - }
> - assert(I == LocalMacroIDs.begin());
> - } else {
> - Reader.addPendingMacroFromPCH(II, &F, MacroDirectivesOffset);
> - }
> + Reader.addPendingMacro(II, &F, MacroDirectivesOffset);
> }
>
> Reader.SetIdentifierInfo(ID, II);
> @@ -1426,6 +1383,7 @@ MacroInfo *ASTReader::ReadMacroRecord(Mo
> PreprocessorRecordTypes RecType =
> (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record);
> switch (RecType) {
> + case PP_MODULE_MACRO:
> case PP_MACRO_DIRECTIVE_HISTORY:
> return Macro;
>
> @@ -1619,24 +1577,9 @@ HeaderFileInfoTrait::ReadData(internal_k
> return HFI;
> }
>
> -void
> -ASTReader::addPendingMacroFromModule(IdentifierInfo *II, ModuleFile *M,
> - GlobalMacroID GMacID,
> - ArrayRef<SubmoduleID> Overrides) {
> - assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
> - SubmoduleID *OverrideData = nullptr;
> - if (!Overrides.empty()) {
> - OverrideData = new (Context) SubmoduleID[Overrides.size() + 1];
> - OverrideData[0] = Overrides.size();
> - for (unsigned I = 0; I != Overrides.size(); ++I)
> - OverrideData[I + 1] = getGlobalSubmoduleID(*M, Overrides[I]);
> - }
> - PendingMacroIDs[II].push_back(PendingMacroInfo(M, GMacID, OverrideData));
> -}
> -
> -void ASTReader::addPendingMacroFromPCH(IdentifierInfo *II,
> - ModuleFile *M,
> - uint64_t MacroDirectivesOffset) {
> +void ASTReader::addPendingMacro(IdentifierInfo *II,
> + ModuleFile *M,
> + uint64_t MacroDirectivesOffset) {
> assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
> PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset));
> }
> @@ -1783,7 +1726,7 @@ void ASTReader::markIdentifierUpToDate(I
> struct ASTReader::ModuleMacroInfo {
> SubmoduleID SubModID;
> MacroInfo *MI;
> - SubmoduleID *Overrides;
> + ArrayRef<SubmoduleID> Overrides;
> // FIXME: Remove this.
> ModuleFile *F;
>
> @@ -1791,11 +1734,7 @@ struct ASTReader::ModuleMacroInfo {
>
> SubmoduleID getSubmoduleID() const { return SubModID; }
>
> - ArrayRef<SubmoduleID> getOverriddenSubmodules() const {
> - if (!Overrides)
> - return None;
> - return llvm::makeArrayRef(Overrides + 1, *Overrides);
> - }
> + ArrayRef<SubmoduleID> getOverriddenSubmodules() const { return Overrides; }
>
> MacroDirective *import(Preprocessor &PP, SourceLocation ImportLoc) const {
> if (!MI)
> @@ -1806,90 +1745,90 @@ struct ASTReader::ModuleMacroInfo {
> }
> };
>
> -ASTReader::ModuleMacroInfo *
> -ASTReader::getModuleMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo) {
> - ModuleMacroInfo Info;
> -
> - uint32_t ID = PMInfo.ModuleMacroData.MacID;
> - if (ID & 1) {
> - // Macro undefinition.
> - Info.SubModID = getGlobalSubmoduleID(*PMInfo.M, ID >> 1);
> - Info.MI = nullptr;
> -
> - // If we've already loaded the #undef of this macro from this module,
> - // don't do so again.
> - if (!LoadedUndefs.insert(std::make_pair(II, Info.SubModID)).second)
> - return nullptr;
> - } else {
> - // Macro definition.
> - GlobalMacroID GMacID = getGlobalMacroID(*PMInfo.M, ID >> 1);
> - assert(GMacID);
> -
> - // If this macro has already been loaded, don't do so again.
> - // FIXME: This is highly dubious. Multiple macro definitions can have the
> - // same MacroInfo (and hence the same GMacID) due to #pragma push_macro etc.
> - if (MacrosLoaded[GMacID - NUM_PREDEF_MACRO_IDS])
> - return nullptr;
> -
> - Info.MI = getMacro(GMacID);
> - Info.SubModID = Info.MI->getOwningModuleID();
> - }
> - Info.Overrides = PMInfo.ModuleMacroData.Overrides;
> - Info.F = PMInfo.M;
> -
> - return new (Context) ModuleMacroInfo(Info);
> -}
> -
> void ASTReader::resolvePendingMacro(IdentifierInfo *II,
> const PendingMacroInfo &PMInfo) {
> - assert(II);
> + ModuleFile &M = *PMInfo.M;
>
> - if (PMInfo.M->Kind != MK_ImplicitModule &&
> - PMInfo.M->Kind != MK_ExplicitModule) {
> - installPCHMacroDirectives(II, *PMInfo.M,
> - PMInfo.PCHMacroData.MacroDirectivesOffset);
> - return;
> - }
> + BitstreamCursor &Cursor = M.MacroCursor;
> + SavedStreamPosition SavedPosition(Cursor);
> + Cursor.JumpToBit(PMInfo.MacroDirectivesOffset);
>
> - // Module Macro.
> + llvm::SmallVector<ModuleMacroInfo *, 8> ModuleMacros;
>
> - ModuleMacroInfo *MMI = getModuleMacro(II, PMInfo);
> - if (!MMI)
> - return;
> + // We expect to see a sequence of PP_MODULE_MACRO records listing exported
> + // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete
> + // macro histroy.
> + RecordData Record;
> + while (true) {
> + llvm::BitstreamEntry Entry =
> + Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
> + if (Entry.Kind != llvm::BitstreamEntry::Record) {
> + Error("malformed block record in AST file");
> + return;
> + }
>
> - Module *Owner = getSubmodule(MMI->getSubmoduleID());
> - if (Owner && Owner->NameVisibility == Module::Hidden) {
> - // Macros in the owning module are hidden. Just remember this macro to
> - // install if we make this module visible.
> - HiddenNamesMap[Owner].HiddenMacros.insert(std::make_pair(II, MMI));
> - } else {
> - installImportedMacro(II, MMI, Owner);
> - }
> -}
> + Record.clear();
> + switch (PreprocessorRecordTypes RecType =
> + (PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
When building with GCC I get a warning here:
[133/299] Building CXX object tools/cl...clangSerialization.dir/ASTReader.cpp.o
/home/jay/svn/llvm-project/llvm/trunk/tools/clang/lib/Serialization/ASTReader.cpp:
In member function ‘void
clang::ASTReader::resolvePendingMacro(clang::IdentifierInfo*, const
clang::ASTReader::PendingMacroInfo&)’:
/home/jay/svn/llvm-project/llvm/trunk/tools/clang/lib/Serialization/ASTReader.cpp:1771:37:
warning: unused variable ‘RecType’ [-Wunused-variable]
switch (PreprocessorRecordTypes RecType =
^
Jay.
More information about the cfe-commits
mailing list