[llvm] [TableGen] Use StringTable for searchable tables (PR #206252)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 27 22:32:22 PDT 2026


================
@@ -396,11 +399,20 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
       OS << "    { ";
       ListSeparator LS;
       for (const auto &Field : Index.Fields) {
-        std::string Repr = primaryRepresentation(
-            Index.Loc, Field, EntryRec->getValueInit(Field.Name));
+        const Init *Value = EntryRec->getValueInit(Field.Name);
+        std::string Repr = primaryRepresentation(Index.Loc, Field, Value);
         if (isa<StringRecTy>(Field.RecType))
           Repr = StringRef(Repr).upper();
-        OS << LS << Repr;
+        if (isa<StringRecTy>(Field.RecType)) {
+          // TODO: if most strings are lower-case already, we can save space by
+          // converting all strings to lower case instead.
----------------
aengelke wrote:

Expanded comment. To give an example:
```c++
static constexpr char RISCVTuneInfoTableStringsStorage[] =
  "\0"
  "generic\0"
  "generic-ooo\0"
  "generic-rv32\0"
  "generic-rv64\0"
  "GENERIC\0"
  "GENERIC-OOO\0"
  "GENERIC-RV32\0"
  "GENERIC-RV64\0"
  ;
```
All stored strings are all-lower-case, but we add the upper-case duplicates just for the case-insensitive comparison. If we used an all-lower-case version for case-insensitive comparison, we could halve the size of the string table. This is especially relevant for the large tables in the SPIRV back-end.

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


More information about the llvm-commits mailing list