[llvm] [SelectionDAG] Table-drive fixed operation names (PR #202841)

David Zbarsky via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 19:49:39 PDT 2026


================
@@ -59,113 +63,99 @@ static cl::opt<bool>
     PrintSDNodeAddrs("print-sdnode-addrs", cl::Hidden,
                      cl::desc("Print addresses of SDNodes when dumping"));
 
+namespace {
+
+// Keep the names in one byte blob so the constant table has no pointers or
+// relocations. Dense integer tables map built-in opcodes to the blob.
+struct FixedOperationNameData {
+#define DAG_NODE_NAME(OPCODE, NAME) char OPCODE[sizeof(NAME)];
+#include "llvm/CodeGen/SelectionDAGOperationNames.def"
+#undef DAG_NODE_NAME
+};
+
+constexpr FixedOperationNameData FixedOperationNames = {
+#define DAG_NODE_NAME(OPCODE, NAME) NAME,
+#include "llvm/CodeGen/SelectionDAGOperationNames.def"
+#undef DAG_NODE_NAME
+};
+
+static_assert(sizeof(FixedOperationNames) <=
+              std::numeric_limits<uint16_t>::max());
+static_assert(alignof(FixedOperationNameData) == alignof(char));
+static_assert(std::is_standard_layout_v<FixedOperationNameData>);
+
+#define DAG_NODE_NAME(OPCODE, NAME)                                            \
+  static_assert(ISD::OPCODE < ISD::BUILTIN_OP_END);                            \
+  static_assert(sizeof(NAME) - 1 <= std::numeric_limits<uint8_t>::max());
+#include "llvm/CodeGen/SelectionDAGOperationNames.def"
+#undef DAG_NODE_NAME
+
+template <typename ValueType, bool StoreLengths>
+constexpr std::array<ValueType, ISD::BUILTIN_OP_END>
+makeFixedOperationNameTable() {
+  std::array<ValueType, ISD::BUILTIN_OP_END> Result{};
+#define DAG_NODE_NAME(OPCODE, NAME)                                            \
+  Result[ISD::OPCODE] = static_cast<ValueType>(                                \
+      StoreLengths ? sizeof(NAME) - 1                                          \
+                   : offsetof(FixedOperationNameData, OPCODE));
+#include "llvm/CodeGen/SelectionDAGOperationNames.def"
+#undef DAG_NODE_NAME
+  return Result;
+}
+
+constexpr auto FixedOperationNameOffsets =
+    makeFixedOperationNameTable<uint16_t, false>();
+constexpr auto FixedOperationNameLengths =
----------------
dzbarsky wrote:

Yep, they’re all null-terminated. I tried dropping the length table and using the terminators directly, but that grew SelectionDAGDumper.cpp.o by about 3 KB. I also tried deriving the lengths from adjacent offsets; that made the object smaller, but the stripped opt binary was the same size and lookup was 10% slower.

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


More information about the llvm-commits mailing list