[clang] [clang][Lex] Unique ModuleMacros with a UniquingSet (NFC) (PR #223270)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 13 12:28:25 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch migrates ModuleMacros in Preprocessor from llvm::FoldingSet
to llvm::UniquingSet.

ModuleMacro keys on a pair of Module * and const IdentifierInfo *.
Switching to UniquingSet allows us to look up macros with a typed key,
eliminating FoldingSetNodeID serialization at lookup sites and removing
ModuleMacro::Profile.

Assisted-by: Antigravity


---
Full diff: https://github.com/llvm/llvm-project/pull/223270.diff


3 Files Affected:

- (modified) clang/include/clang/Lex/MacroInfo.h (+3-9) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+1-1) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+2-8) 


``````````diff
diff --git a/clang/include/clang/Lex/MacroInfo.h b/clang/include/clang/Lex/MacroInfo.h
index 60048688a9a33d..e5dbc7f92a9ac1 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -511,7 +511,7 @@ MacroDirective::DefInfo::getPreviousDefinition() {
 /// the final directive for a macro name within a module. These entities also
 /// represent the macro override graph.
 ///
-/// These are stored in a FoldingSet in the preprocessor.
+/// These are stored in a UniquingSet in the preprocessor.
 class ModuleMacro : public llvm::FoldingSetNode {
   friend class Preprocessor;
 
@@ -543,14 +543,8 @@ class ModuleMacro : public llvm::FoldingSetNode {
                              const IdentifierInfo *II, MacroInfo *Macro,
                              ArrayRef<ModuleMacro *> Overrides);
 
-  void Profile(llvm::FoldingSetNodeID &ID) const {
-    return Profile(ID, OwningModule, II);
-  }
-
-  static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule,
-                      const IdentifierInfo *II) {
-    ID.AddPointer(OwningModule);
-    ID.AddPointer(II);
+  std::pair<Module *, const IdentifierInfo *> getKey() const {
+    return {OwningModule, II};
   }
 
   /// Get the name of the macro.
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index d94f3d2cbe8ed5..31b68a0fd0670e 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1091,7 +1091,7 @@ class Preprocessor {
   llvm::SmallSetVector<Module *, 2> AffectingClangModules;
 
   /// The set of known macros exported from modules.
-  llvm::FoldingSet<ModuleMacro> ModuleMacros;
+  llvm::UniquingSet<ModuleMacro> ModuleMacros;
 
   /// The names of potential module macros that we've not yet processed.
   llvm::SmallVector<IdentifierInfo *, 32> PendingModuleMacroNames;
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index a8b9bcd4e4572a..83f78700a4e72b 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -131,11 +131,8 @@ ModuleMacro *Preprocessor::addModuleMacro(Module *Mod, IdentifierInfo *II,
                                           MacroInfo *Macro,
                                           ArrayRef<ModuleMacro *> Overrides,
                                           bool &New) {
-  llvm::FoldingSetNodeID ID;
-  ModuleMacro::Profile(ID, Mod, II);
-
   llvm::FoldingSetInsertToken InsertToken;
-  if (auto *MM = ModuleMacros.lookup(ID, InsertToken)) {
+  if (auto *MM = ModuleMacros.lookup({Mod, II}, InsertToken)) {
     New = false;
     return MM;
   }
@@ -168,11 +165,8 @@ ModuleMacro *Preprocessor::addModuleMacro(Module *Mod, IdentifierInfo *II,
 
 ModuleMacro *Preprocessor::getModuleMacro(Module *Mod,
                                           const IdentifierInfo *II) {
-  llvm::FoldingSetNodeID ID;
-  ModuleMacro::Profile(ID, Mod, II);
-
   llvm::FoldingSetInsertToken InsertToken;
-  return ModuleMacros.lookup(ID, InsertToken);
+  return ModuleMacros.lookup({Mod, II}, InsertToken);
 }
 
 void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II,

``````````

</details>


https://github.com/llvm/llvm-project/pull/223270


More information about the cfe-commits mailing list