r177197 - [modules] Don't record the macros from the predefines buffer.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Mar 15 15:43:10 PDT 2013
Author: akirtzidis
Date: Fri Mar 15 17:43:10 2013
New Revision: 177197
URL: http://llvm.org/viewvc/llvm-project?rev=177197&view=rev
Log:
[modules] Don't record the macros from the predefines buffer.
These will be available in the current translation unit anyway, for
modules they only waste space and deserialization time.
Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=177197&r1=177196&r2=177197&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Mar 15 17:43:10 2013
@@ -1793,6 +1793,22 @@ static int compareMacroDefinitions(const
return X.first->getName().compare(Y.first->getName());
}
+static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
+ const Preprocessor &PP) {
+ if (MD->getInfo()->isBuiltinMacro())
+ return true;
+
+ if (IsModule) {
+ SourceLocation Loc = MD->getLocation();
+ if (Loc.isInvalid())
+ return true;
+ if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID())
+ return true;
+ }
+
+ return false;
+}
+
/// \brief Writes the block containing the serialized form of the
/// preprocessor.
///
@@ -1851,6 +1867,9 @@ void ASTWriter::WritePreprocessor(const
for (MacroDirective *MD = MacrosToEmit[I].second; MD;
MD = MD->getPrevious()) {
+ if (shouldIgnoreMacro(MD, IsModule, PP))
+ continue;
+
MacroID ID = getMacroRef(MD);
if (!ID)
continue;
@@ -2749,7 +2768,7 @@ class ASTIdentifierTableTrait {
return false;
if (Macro || (Macro = PP.getMacroDirectiveHistory(II)))
- return !Macro->getInfo()->isBuiltinMacro() &&
+ return !shouldIgnoreMacro(Macro, IsModule, PP) &&
(!IsModule || Macro->isPublic());
return false;
@@ -2780,6 +2799,8 @@ public:
DataLen += 2; // 2 bytes for flags
if (hadMacroDefinition(II, Macro)) {
for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
+ if (shouldIgnoreMacro(M, IsModule, PP))
+ continue;
if (Writer.getMacroRef(M) != 0)
DataLen += 4;
}
@@ -2832,6 +2853,8 @@ public:
if (HadMacroDefinition) {
// Write all of the macro IDs associated with this identifier.
for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
+ if (shouldIgnoreMacro(M, IsModule, PP))
+ continue;
if (MacroID ID = Writer.getMacroRef(M))
clang::io::Emit32(Out, ID);
}
More information about the cfe-commits
mailing list