Skip to content

Conversation

s-barannikov
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2025

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

Changes

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

1 Files Affected:

  • (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+20-41)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 681f4cc9614eb..083d78c4986f0 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1548,7 +1548,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
       ScopeStack.push_back(SkipTo);
       LLVM_DEBUG(dbgs() << Loc << ": OPC_Scope(" << SkipTo - DecodeTable
                         << ")\n");
-      break;
+      continue;
     }
     case OPC_ExtractField: {
       // Decode the start value.
@@ -1560,7 +1560,7 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
       CurFieldValue = fieldFromInstruction(insn, Start, Len);
       LLVM_DEBUG(dbgs() << Loc << ": OPC_ExtractField(" << Start << ", "
                    << Len << "): " << CurFieldValue << "\n");
-      break;
+      continue;
     }
     case OPC_FilterValueOrSkip: {
       // Decode the field value.
@@ -1572,12 +1572,11 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
       LLVM_DEBUG(dbgs() << Loc << ": OPC_FilterValueOrSkip(" << Val << ", "
                         << SkipTo - DecodeTable << ") "
                         << (Failed ? "FAIL, " : "PASS\n"));
-
-      if (Failed) {
-        Ptr = SkipTo;
-        LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
-      }
-      break;
+      if (!Failed)
+        continue;
+      Ptr = SkipTo;
+      LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
+      continue;
     }
     case OPC_FilterValue: {
       // Decode the field value.
@@ -1586,15 +1585,8 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
 
       LLVM_DEBUG(dbgs() << Loc << ": OPC_FilterValue(" << Val << ") "
                         << (Failed ? "FAIL, " : "PASS\n"));
-
-      if (Failed) {
-        if (ScopeStack.empty()) {
-          LLVM_DEBUG(dbgs() << "returning Fail\n");
-          return MCDisassembler::Fail;
-        }
-        Ptr = ScopeStack.pop_back_val();
-        LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
-      }
+      if (!Failed)
+        continue;
       break;
     }
     case OPC_CheckField: {
@@ -1615,14 +1607,8 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
                         << ", " << ExpectedValue << "): FieldValue = "
                         << FieldValue << ", ExpectedValue = " << ExpectedValue
                         << ": " << (Failed ? "FAIL, " : "PASS\n"););
-      if (Failed) {
-        if (ScopeStack.empty()) {
-          LLVM_DEBUG(dbgs() << "returning Fail\n");
-          return MCDisassembler::Fail;
-        }
-        Ptr = ScopeStack.pop_back_val();
-        LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
-      }
+      if (!Failed)
+        continue;
       break;
     })";
   if (TableInfo.HasCheckPredicate) {
@@ -1635,15 +1621,8 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
 
       LLVM_DEBUG(dbgs() << Loc << ": OPC_CheckPredicate(" << PIdx << "): "
                         << (Failed ? "FAIL, " : "PASS\n"););
-
-      if (Failed) {
-        if (ScopeStack.empty()) {
-          LLVM_DEBUG(dbgs() << "returning Fail\n");
-          return MCDisassembler::Fail;
-        }
-        Ptr = ScopeStack.pop_back_val();
-        LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
-      }
+      if (!Failed)
+        continue;
       break;
     })";
   }
@@ -1672,12 +1651,6 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
         return S;
       }
       assert(S == MCDisassembler::Fail);
-      if (ScopeStack.empty()) {
-        LLVM_DEBUG(dbgs() << "returning Fail\n");
-        return MCDisassembler::Fail;
-      }
-      Ptr = ScopeStack.pop_back_val();
-      LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
       // Reset decode status. This also drops a SoftFail status that could be
       // set before the decode attempt.
       S = MCDisassembler::Success;
@@ -1693,11 +1666,17 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
       if (Failed)
         S = MCDisassembler::SoftFail;
       LLVM_DEBUG(dbgs() << Loc << ": OPC_SoftFail: " << (Failed ? "FAIL\n" : "PASS\n"));
-      break;
+      continue;
     })";
   }
   OS << R"(
     }
+    if (ScopeStack.empty()) {
+      LLVM_DEBUG(dbgs() << "returning Fail\n");
+      return MCDisassembler::Fail;
+    }
+    Ptr = ScopeStack.pop_back_val();
+    LLVM_DEBUG(dbgs() << "continuing at " << Ptr - DecodeTable << '\n');
   }
   llvm_unreachable("bogosity detected in disassembler state machine!");
 }

@s-barannikov s-barannikov enabled auto-merge (squash) September 18, 2025 10:39
@s-barannikov s-barannikov merged commit 3defab3 into llvm:main Sep 18, 2025
11 checks passed
@s-barannikov s-barannikov deleted the tablegen/decoder/sink-scope-check branch September 18, 2025 11:09
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