[clang] 4674e30 - [Tooling/Inclusion] Refactor to use tables for compile time

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 04:15:18 PDT 2023


Author: Benjamin Kramer
Date: 2023-10-24T13:15:02+02:00
New Revision: 4674e303d2603f5d3c8faba2de676ed6ad0299a0

URL: https://github.com/llvm/llvm-project/commit/4674e303d2603f5d3c8faba2de676ed6ad0299a0
DIFF: https://github.com/llvm/llvm-project/commit/4674e303d2603f5d3c8faba2de676ed6ad0299a0.diff

LOG: [Tooling/Inclusion] Refactor to use tables for compile time

The macro expansion takes 13s and generates an 1.5M obj file, table uses
2s and 680k .o file.

Sanitizers take multiple minutes to compile the old version, while
having negligible overhead on the new version.

No change in functionality.

Added: 
    

Modified: 
    clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 664f3b76f661281..e409b8481e5fc9c 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -55,20 +55,26 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) {
 }
 
 static int countSymbols(Lang Language) {
-  llvm::DenseSet<llvm::StringRef> Set;
-#define SYMBOL(Name, NS, Header) Set.insert(#NS #Name);
+  ArrayRef<const char*> Symbols;
+#define SYMBOL(Name, NS, Header) #NS #Name,
   switch (Language) {
   case Lang::C:
+    static constexpr const char *CSymbols[] = {
 #include "CSymbolMap.inc"
+    };
+    Symbols = CSymbols;
     break;
   case Lang::CXX:
+    static constexpr const char *CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
 #include "StdTsSymbolMap.inc"
+    };
+    Symbols = CXXSymbols;
     break;
   }
 #undef SYMBOL
-  return Set.size();
+  return llvm::DenseSet<StringRef>(Symbols.begin(), Symbols.end()).size();
 }
 
 static int initialize(Lang Language) {
@@ -127,15 +133,29 @@ static int initialize(Lang Language) {
     NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
     NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
   };
-#define SYMBOL(Name, NS, Header) Add(#NS #Name, strlen(#NS), #Header);
+
+  struct Symbol {
+    const char *QName;
+    unsigned NSLen;
+    const char *HeaderName;
+  };
+#define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size(), #Header},
   switch (Language) {
   case Lang::C:
+    static constexpr Symbol CSymbols[] = {
 #include "CSymbolMap.inc"
+    };
+    for (const Symbol &S : CSymbols)
+      Add(S.QName, S.NSLen, S.HeaderName);
     break;
   case Lang::CXX:
+    static constexpr Symbol CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
 #include "StdTsSymbolMap.inc"
+    };
+    for (const Symbol &S : CXXSymbols)
+      Add(S.QName, S.NSLen, S.HeaderName);
     break;
   }
 #undef SYMBOL


        


More information about the cfe-commits mailing list