[llvm] [NFC][TableGen] Emit more readable builtin string table. (PR #105445)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 05:46:13 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/105445
>From 6ac2624c5cbe1fa0fc9e3bf0d93ed8a3f3d76ce7 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 20 Aug 2024 15:09:52 -0700
Subject: [PATCH] [NFC][TableGen] Emit more readable builtin string table.
- Adopt `SequenceToOffsetTable` to emit the string table in
`EmitIntrinsicToBuiltinMap`.
- `SequenceToOffsetTable` emits a string table using string literal
concatenation of individual null terminated fragments, one fragment on each
line, making the table more readable as well searchable.
- Adopt `StringRef` to be used as the sequence type in `SequenceToOffsetTable`
by providing `value_type` and reverse iterators.
- Reduces string table size for both Clang and MS builtins by several
bytes: Clang: 134915 -> 134001, MS: 68->56 bytes.
---
.../llvm/TableGen/StringToOffsetTable.h | 22 +++++++++++++++++++
llvm/utils/TableGen/IntrinsicEmitter.cpp | 4 +---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/TableGen/StringToOffsetTable.h b/llvm/include/llvm/TableGen/StringToOffsetTable.h
index 7fb9d02d77c704..b1121f919f68e6 100644
--- a/llvm/include/llvm/TableGen/StringToOffsetTable.h
+++ b/llvm/include/llvm/TableGen/StringToOffsetTable.h
@@ -52,6 +52,28 @@ class StringToOffsetTable {
return II->second;
}
+ // Emit the string using string literal concatenation, for better readability
+ // and searchability.
+ void EmitStringLiteralDef(raw_ostream &OS, const Twine &Decl,
+ const Twine &Indent = " ") const {
+ OS << "\n"
+ << Indent << "#ifdef __GNUC__\n"
+ << Indent << "#pragma GCC diagnostic push\n"
+ << Indent << "#pragma GCC diagnostic ignored \"-Woverlength-strings\"\n"
+ << Indent << "#endif\n"
+ << Indent << Decl << " = {\n";
+ for (StringRef Str : split(AggregateString, '\0')) {
+ OS << Indent << " \"";
+ OS.write_escaped(Str);
+ OS << "\\0\"\n";
+ }
+ OS << Indent << "};\n"
+ << Indent << "#ifdef __GNUC__\n"
+ << Indent << "#pragma GCC diagnostic pop\n"
+ << Indent << "#endif\n";
+ }
+
+ // Emit the string as one single string.
void EmitString(raw_ostream &O) {
// Escape the string.
SmallString<256> Str;
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 5d972157828784..8e536c99f627f5 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -669,9 +669,7 @@ Intrinsic::getIntrinsicFor{1}Builtin(StringRef TargetPrefix,
}
if (!Table.empty()) {
- OS << " static constexpr char BuiltinNames[] = {\n";
- Table.EmitCharArray(OS);
- OS << " };\n\n";
+ Table.EmitStringLiteralDef(OS, "static constexpr char BuiltinNames[]");
OS << R"(
struct BuiltinEntry {
More information about the llvm-commits
mailing list