[llvm] [SelectionDAG] Table-drive fixed operation names (PR #202841)
David Zbarsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 06:28:30 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:
I'll check! (BTW this PR is still in draft, it's not intended for other humans to look at yet :) )
https://github.com/llvm/llvm-project/pull/202841
More information about the llvm-commits
mailing list