Skip to content

Conversation

@s-barannikov
Copy link
Contributor

No description provided.

@s-barannikov s-barannikov enabled auto-merge (squash) August 22, 2025 22:06
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

Changes

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

1 Files Affected:

  • (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+22-19)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index c502e30edf578..e7bd26a35ce11 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -199,6 +199,16 @@ class InstructionEncoding {
   /// Returns a mask of bits that should be considered unknown during decoding.
   const APInt &getSoftFailBits() const { return SoftFailBits; }
 
+  /// Returns the known bits of this encoding that must match for
+  /// successful decoding.
+  KnownBits getMandatoryBits() const {
+    KnownBits EncodingBits = getInstBits();
+    // Clear all bits that are allowed to change according to SoftFail mask.
+    EncodingBits.Zero &= ~getSoftFailBits();
+    EncodingBits.One &= ~getSoftFailBits();
+    return EncodingBits;
+  }
+
   /// Returns the name of the function to use for decoding, or an empty string
   /// if the decoder is generated.
   StringRef getDecoderMethod() const { return DecoderMethod; }
@@ -559,15 +569,6 @@ class FilterChooser {
   }
 
 protected:
-  KnownBits getMandatoryEncodingBits(unsigned EncodingID) const {
-    const InstructionEncoding &Encoding = Encodings[EncodingID];
-    KnownBits EncodingBits = Encoding.getInstBits();
-    // Clear all bits that are allowed to change according to SoftFail mask.
-    EncodingBits.Zero &= ~Encoding.getSoftFailBits();
-    EncodingBits.One &= ~Encoding.getSoftFailBits();
-    return EncodingBits;
-  }
-
   /// dumpStack - dumpStack traverses the filter chooser chain and calls
   /// dumpFilterArray on each filter chooser up to the top level one.
   void dumpStack(raw_ostream &OS, indent Indent, unsigned PadToWidth) const;
@@ -655,8 +656,8 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
   assert(StartBit + NumBits - 1 < Owner.FilterBits.getBitWidth());
 
   for (unsigned EncodingID : Owner.EncodingIDs) {
-    // Populates the insn given the uid.
-    KnownBits EncodingBits = Owner.getMandatoryEncodingBits(EncodingID);
+    const InstructionEncoding &Encoding = Owner.Encodings[EncodingID];
+    KnownBits EncodingBits = Encoding.getMandatoryBits();
 
     // Scans the segment for possibly well-specified encoding bits.
     KnownBits FieldBits = EncodingBits.extractBits(NumBits, StartBit);
@@ -1381,7 +1382,8 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
 // Emits table entries to decode the singleton.
 void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
                                             unsigned EncodingID) const {
-  KnownBits EncodingBits = getMandatoryEncodingBits(EncodingID);
+  const InstructionEncoding &Encoding = Encodings[EncodingID];
+  KnownBits EncodingBits = Encoding.getMandatoryBits();
 
   // Look for islands of undecoded bits of the singleton.
   std::vector<Island> Islands = getIslands(EncodingBits);
@@ -1425,7 +1427,6 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
   // decoder method indicates that additional processing should be done to see
   // if there is any other instruction that also matches the bitpattern and
   // can decode it.
-  const InstructionEncoding &Encoding = Encodings[EncodingID];
   const uint8_t DecoderOp =
       Encoding.hasCompleteDecoder()
           ? MCD::OPC_Decode
@@ -1484,7 +1485,8 @@ bool FilterChooser::filterProcessor(ArrayRef<bitAttr_t> BitAttrs,
     assert(EncodingIDs.size() == 3);
 
     for (unsigned EncodingID : EncodingIDs) {
-      KnownBits EncodingBits = getMandatoryEncodingBits(EncodingID);
+      const InstructionEncoding &Encoding = Encodings[EncodingID];
+      KnownBits EncodingBits = Encoding.getMandatoryBits();
 
       // Look for islands of undecoded bits of any instruction.
       std::vector<Island> Islands = getIslands(EncodingBits);
@@ -1675,7 +1677,8 @@ void FilterChooser::doFilter() {
       BitAttrs[BitIndex] = ATTR_FILTERED;
 
   for (unsigned EncodingID : EncodingIDs) {
-    KnownBits EncodingBits = getMandatoryEncodingBits(EncodingID);
+    const InstructionEncoding &Encoding = Encodings[EncodingID];
+    KnownBits EncodingBits = Encoding.getMandatoryBits();
 
     for (unsigned BitIndex = 0; BitIndex != FilterWidth; ++BitIndex) {
       bool IsKnown = EncodingBits.Zero[BitIndex] || EncodingBits.One[BitIndex];
@@ -1732,10 +1735,10 @@ void FilterChooser::doFilter() {
 
   // Dump encodings.
   for (unsigned EncodingID : EncodingIDs) {
-    const InstructionEncoding &Enc = Encodings[EncodingID];
-    errs() << Indent << indent(PadToWidth - Enc.getBitWidth());
-    printKnownBits(errs(), getMandatoryEncodingBits(EncodingID), '_');
-    errs() << "  " << Enc.getName() << '\n';
+    const InstructionEncoding &Encoding = Encodings[EncodingID];
+    errs() << Indent << indent(PadToWidth - Encoding.getBitWidth());
+    printKnownBits(errs(), Encoding.getMandatoryBits(), '_');
+    errs() << "  " << Encoding.getName() << '\n';
   }
   PrintFatalError("Decoding conflict encountered");
 }

@s-barannikov s-barannikov force-pushed the tablegen/decoder/move-mandatory-bits branch from 87c8a75 to 2524e1a Compare August 22, 2025 22:08
@s-barannikov s-barannikov merged commit 4028896 into llvm:main Aug 22, 2025
9 checks passed
@s-barannikov s-barannikov deleted the tablegen/decoder/move-mandatory-bits branch August 24, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants