[llvm] [TableGen][Decoder] Always handle `bits<0>` (PR #159951)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 20 15:19:34 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/159951.diff


2 Files Affected:

- (modified) llvm/utils/TableGen/Common/InstructionEncoding.cpp (+7) 
- (modified) llvm/utils/TableGen/DecoderEmitter.cpp (-2) 


``````````diff
diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.cpp b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
index 7260ee3d9b534..40ed18a52e075 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 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

``````````

</details>


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


More information about the llvm-commits mailing list