r232140 - Deduplicate #undef directives imported from multiple modules.
Richard Smith
richard-llvm at metafoo.co.uk
Thu Mar 12 21:05:01 PDT 2015
Author: rsmith
Date: Thu Mar 12 23:05:01 2015
New Revision: 232140
URL: http://llvm.org/viewvc/llvm-project?rev=232140&view=rev
Log:
Deduplicate #undef directives imported from multiple modules.
No functionality change, but deeply-importing module files are smaller and
faster now.
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=232140&r1=232139&r2=232140&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Mar 12 23:05:01 2015
@@ -539,6 +539,14 @@ private:
/// been loaded.
std::vector<MacroInfo *> MacrosLoaded;
+ typedef std::pair<IdentifierInfo *, serialization::SubmoduleID>
+ LoadedMacroInfo;
+
+ /// \brief A set of #undef directives that we have loaded; used to
+ /// deduplicate the same #undef information coming from multiple module
+ /// files.
+ llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
+
typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
GlobalMacroMapType;
@@ -1844,7 +1852,8 @@ public:
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
unsigned LocalID);
- ModuleMacroInfo *getModuleMacro(const PendingMacroInfo &PMInfo);
+ ModuleMacroInfo *getModuleMacro(IdentifierInfo *II,
+ const PendingMacroInfo &PMInfo);
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=232140&r1=232139&r2=232140&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Mar 12 23:05:01 2015
@@ -826,7 +826,7 @@ IdentifierInfo *ASTIdentifierLookupTrait
uint32_t LocalMacroID =
endian::readNext<uint32_t, little, unaligned>(d);
DataLen -= 4;
- if (LocalMacroID == 0xdeadbeef) break;
+ if (LocalMacroID == (uint32_t)-1) break;
LocalMacroIDs.push_back(LocalMacroID);
}
}
@@ -1807,7 +1807,7 @@ struct ASTReader::ModuleMacroInfo {
};
ASTReader::ModuleMacroInfo *
-ASTReader::getModuleMacro(const PendingMacroInfo &PMInfo) {
+ASTReader::getModuleMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo) {
ModuleMacroInfo Info;
uint32_t ID = PMInfo.ModuleMacroData.MacID;
@@ -1815,6 +1815,11 @@ ASTReader::getModuleMacro(const PendingM
// 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);
@@ -1848,7 +1853,7 @@ void ASTReader::resolvePendingMacro(Iden
// Module Macro.
- ModuleMacroInfo *MMI = getModuleMacro(PMInfo);
+ ModuleMacroInfo *MMI = getModuleMacro(II, PMInfo);
if (!MMI)
return;
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=232140&r1=232139&r2=232140&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Mar 12 23:05:01 2015
@@ -3347,6 +3347,7 @@ public:
using namespace llvm::support;
endian::Writer<little> LE(Out);
+ assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen);
LE.write<uint16_t>(DataLen);
// We emit the key length after the data length so that every
// string is preceded by a 16-bit length. This matches the PTH
@@ -3425,7 +3426,7 @@ public:
}
emitMacroOverrides(Out, getOverriddenSubmodules(MD, Scratch));
}
- LE.write<uint32_t>(0xdeadbeef);
+ LE.write<uint32_t>((uint32_t)-1);
}
}
More information about the cfe-commits
mailing list