[llvm] [TableGen][Decoder] Always handle `bits<0>` (PR #159951)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 15:22:14 PDT 2025
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/159951
>From e090032bd3eaa5c4e2c44f1a255e35637e2fa8c0 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Sun, 21 Sep 2025 01:17:44 +0300
Subject: [PATCH] [TableGen][Decoder] Always handle `bits<0>`
Previously, `bits<0>` only had effect if `ignore-non-decodable-operands`
wasn't specified. Handle it even if the option wasn't specified. This
should allow for a smoother transition.
---
llvm/utils/TableGen/Common/InstructionEncoding.cpp | 7 +++++++
llvm/utils/TableGen/DecoderEmitter.cpp | 2 --
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.cpp b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
index 7260ee3d9b534..945cba5f5ac14 100644
--- a/llvm/utils/TableGen/Common/InstructionEncoding.cpp
+++ b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
@@ -316,6 +316,13 @@ static void addOneOperandFields(const Record *EncodingDef,
else
OpInfo.addField(I, J - I, Offset);
}
+
+ // We found a field in InstructionEncoding record that corresponds to the
+ // named operand, but that field has no constant bits and doesn't contribute
+ // to the Inst field. Treat it as if there was no field for that operand.
+ // TODO: Warn that such a field should be defined as `bits<0>`.
+ if (!OpInfo.InitValue && OpInfo.fields().empty())
+ OpInfo.HasNoEncoding = true;
}
void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index e83df47d541c6..961dc2815f6b9 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -696,8 +696,6 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
// Special case for 'bits<0>'.
if (OpInfo.Fields.empty() && !OpInfo.InitValue) {
- if (IgnoreNonDecodableOperands)
- return;
assert(!OpInfo.Decoder.empty());
// The operand has no encoding, so the corresponding argument is omitted.
// This avoids confusion and allows the function to be overloaded if the
More information about the llvm-commits
mailing list