[clang] d584468 - [C++20] [Modules] Don't emit macro definitions with named module
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 17 19:12:21 PST 2022
Author: Chuanqi Xu
Date: 2022-11-18T11:11:17+08:00
New Revision: d5844685810980399397a4310b943532361790ef
URL: https://github.com/llvm/llvm-project/commit/d5844685810980399397a4310b943532361790ef
DIFF: https://github.com/llvm/llvm-project/commit/d5844685810980399397a4310b943532361790ef.diff
LOG: [C++20] [Modules] Don't emit macro definitions with named module
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.
Added:
Modified:
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/cxx20-module-file-info-macros.cpp
Removed:
################################################################################
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 95ed51a90c18..e944d2e2a2d1 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -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<>>());
diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 422589702948..bc7df1c9f50b 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -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:
More information about the cfe-commits
mailing list