Skip to content

Conversation

s-barannikov
Copy link
Contributor

No description provided.

@s-barannikov s-barannikov enabled auto-merge (squash) August 28, 2025 15:49
@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

Changes

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

1 Files Affected:

  • (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+11-30)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index ecdc48775c9c1..a32f5f2d68171 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -163,7 +163,7 @@ class InstructionEncoding {
 
   /// Mask of bits that should be considered unknown during decoding.
   /// This is the value of the `SoftFail` field.
-  APInt SoftFailBits;
+  APInt SoftFailMask;
 
   /// The name of the function to use for decoding. May be an empty string,
   /// meaning the decoder is generated.
@@ -197,7 +197,7 @@ class InstructionEncoding {
   const KnownBits &getInstBits() const { return InstBits; }
 
   /// Returns a mask of bits that should be considered unknown during decoding.
-  const APInt &getSoftFailBits() const { return SoftFailBits; }
+  const APInt &getSoftFailMask() const { return SoftFailMask; }
 
   /// Returns the known bits of this encoding that must match for
   /// successful decoding.
@@ -205,8 +205,8 @@ class InstructionEncoding {
     KnownBits EncodingBits = InstBits;
     // Mark all bits that are allowed to change according to SoftFail mask
     // as unknown.
-    EncodingBits.Zero &= ~SoftFailBits;
-    EncodingBits.One &= ~SoftFailBits;
+    EncodingBits.Zero &= ~SoftFailMask;
+    EncodingBits.One &= ~SoftFailMask;
     return EncodingBits;
   }
 
@@ -1243,32 +1243,13 @@ void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
 void DecoderTableBuilder::emitSoftFailTableEntry(unsigned EncodingID) const {
   const InstructionEncoding &Encoding = Encodings[EncodingID];
   const KnownBits &InstBits = Encoding.getInstBits();
-  const APInt &SFBits = Encoding.getSoftFailBits();
+  const APInt &SoftFailMask = Encoding.getSoftFailMask();
 
-  if (SFBits.isZero())
+  if (SoftFailMask.isZero())
     return;
 
-  unsigned EncodingWidth = InstBits.getBitWidth();
-  APInt PositiveMask(EncodingWidth, 0);
-  APInt NegativeMask(EncodingWidth, 0);
-  for (unsigned i = 0; i != EncodingWidth; ++i) {
-    if (!SFBits[i])
-      continue;
-
-    if (InstBits.Zero[i]) {
-      // The bit is meant to be false, so emit a check to see if it is true.
-      PositiveMask.setBit(i);
-    } else if (InstBits.One[i]) {
-      // The bit is meant to be true, so emit a check to see if it is false.
-      NegativeMask.setBit(i);
-    }
-  }
-
-  bool NeedPositiveMask = PositiveMask.getBoolValue();
-  bool NeedNegativeMask = NegativeMask.getBoolValue();
-
-  if (!NeedPositiveMask && !NeedNegativeMask)
-    return;
+  APInt PositiveMask = InstBits.Zero & SoftFailMask;
+  APInt NegativeMask = InstBits.One & SoftFailMask;
 
   TableInfo.Table.insertOpcode(MCD::OPC_SoftFail);
   TableInfo.Table.insertULEB128(PositiveMask.getZExtValue());
@@ -1737,7 +1718,7 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
 
 void InstructionEncoding::parseVarLenEncoding(const VarLenInst &VLI) {
   InstBits = KnownBits(VLI.size());
-  SoftFailBits = APInt(VLI.size(), 0);
+  SoftFailMask = APInt(VLI.size(), 0);
 
   // Parse Inst field.
   unsigned I = 0;
@@ -1806,7 +1787,7 @@ void InstructionEncoding::parseFixedLenEncoding(
   ArrayRef<const Init *> ActiveInstBits =
       RecordInstBits.getBits().take_front(BitWidth);
   InstBits = KnownBits(BitWidth);
-  SoftFailBits = APInt(BitWidth, 0);
+  SoftFailMask = APInt(BitWidth, 0);
 
   // Parse Inst field.
   for (auto [I, V] : enumerate(ActiveInstBits)) {
@@ -1848,7 +1829,7 @@ void InstructionEncoding::parseFixedLenEncoding(
                            "to be fully defined (0 or 1, not '?')",
                            I));
       }
-      SoftFailBits.setBit(I);
+      SoftFailMask.setBit(I);
     }
   }
 }

@s-barannikov s-barannikov merged commit ca5d195 into llvm:main Aug 28, 2025
11 checks passed
@s-barannikov s-barannikov deleted the tablegen/decoder/softfail branch August 28, 2025 17:12
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