Skip to content

Commit

Permalink
[C++20] [Modules] Don't emit macro definitions with named module
Browse files Browse the repository at this point in the history
It is meaningless to emit macro definitions for named modules. With some
small experiments, the size of the module for the named modules reduced
2%~4% after this patch.
  • Loading branch information
ChuanqiXu9 committed Nov 18, 2022
1 parent ae43420 commit d584468
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
13 changes: 8 additions & 5 deletions clang/lib/Serialization/ASTWriter.cpp
Expand Up @@ -2318,11 +2318,14 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
// Construct the list of identifiers with macro directives that need to be
// serialized.
SmallVector<const IdentifierInfo *, 128> MacroIdentifiers;
for (auto &Id : PP.getIdentifierTable())
if (Id.second->hadMacroDefinition() &&
(!Id.second->isFromAST() ||
Id.second->hasChangedSinceDeserialization()))
MacroIdentifiers.push_back(Id.second);
// It is meaningless to emit macros for named modules. It only wastes times
// and spaces.
if (!isWritingStdCXXNamedModules())
for (auto &Id : PP.getIdentifierTable())
if (Id.second->hadMacroDefinition() &&
(!Id.second->isFromAST() ||
Id.second->hasChangedSinceDeserialization()))
MacroIdentifiers.push_back(Id.second);
// Sort the set of macro definitions that need to be serialized by the
// name of the macro, to provide a stable ordering.
llvm::sort(MacroIdentifiers, llvm::deref<std::less<>>());
Expand Down
11 changes: 1 addition & 10 deletions clang/test/Modules/cxx20-module-file-info-macros.cpp
Expand Up @@ -62,13 +62,4 @@ module;
#include "foo.h"
export module M;
#define M_Module 43
// FIXME: It is meaningless for named modules to emit macro definitions.
// It wastes the time and spaces completely.
// CHECK: Macro Definitions:
// CHECK-DAG: M_Module
// CHECK-DAG: REDEFINE
// CHECK-DAG: FUNC_Macro
// CHECK-DAG: TO_BE_UNDEF
// CHECK-DAG: FOO
// CHECK-DAG: CONSTANT
// CHECK-NEXT: ===
// CHECK-NOT: Macro Definitions:

0 comments on commit d584468

Please sign in to comment.