aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DecoderEmitter.cpp
diff options
context:
space:
mode:
authorSergei Barannikov <barannikov88@gmail.com>2025-09-18 14:09:35 +0300
committerGitHub <noreply@github.com>2025-09-18 11:09:35 +0000
commit3defab36b73d60e616f5d6fe0e88e435c3dfc0dc (patch)
tree13e0336731157df95cf73d9cbdfd1c65ab23ce31 /llvm/utils/TableGen/DecoderEmitter.cpp
parentf5ffedf81a1db4f0e149acb1b49cdc940e8c4233 (diff)
downloadllvm-3defab36b73d60e616f5d6fe0e88e435c3dfc0dc.zip
llvm-3defab36b73d60e616f5d6fe0e88e435c3dfc0dc.tar.gz
llvm-3defab36b73d60e616f5d6fe0e88e435c3dfc0dc.tar.bz2
[TableGen][DecoderEmitter] Sink repeated code after the switch (NFC) (#159549)
Diffstat (limited to 'llvm/utils/TableGen/DecoderEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/DecoderEmitter.cpp61
1 files changed, 20 insertions, 41 deletions
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 681f4cc..083d78c 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!");
}