[llvm] [NFC][TableGen] Code cleanup in Wasm disassember emitter (PR #135992)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 09:26:46 PDT 2025
================
@@ -116,53 +121,43 @@ void llvm::emitWebAssemblyDisassemblerTables(
}
// See if we already have stored this sequence before. This is not
// strictly necessary but makes the table really small.
- size_t OperandStart = OperandTable.size();
- if (CurOperandList.size() <= OperandTable.size()) {
- for (size_t J = 0; J <= OperandTable.size() - CurOperandList.size();
- ++J) {
- size_t K = 0;
- for (; K < CurOperandList.size(); ++K) {
- if (OperandTable[J + K] != CurOperandList[K])
- break;
- }
- if (K == CurOperandList.size()) {
- OperandStart = J;
- break;
- }
- }
- }
+ auto SearchI =
+ std::search(OperandTable.begin(), OperandTable.end(),
+ CurOperandList.begin(), CurOperandList.end());
+ OS << std::distance(OperandTable.begin(), SearchI);
// Store operands if no prior occurrence.
- if (OperandStart == OperandTable.size()) {
+ if (SearchI == OperandTable.end())
llvm::append_range(OperandTable, CurOperandList);
- }
- OS << OperandStart;
} else {
auto PrefixIt = OpcodeTable.find(I);
// If we have a non-empty table for it that's not 0, this is a prefix.
- if (PrefixIt != OpcodeTable.end() && I && !Prefix) {
+ if (PrefixIt != OpcodeTable.end() && I && !Prefix)
OS << " { 0, ET_Prefix, 0, 0";
- } else {
+ else
OS << " { 0, ET_Unused, 0, 0";
- }
}
OS << " },\n";
}
OS << "};\n\n";
}
// Create a table of all operands:
- OS << "const uint8_t OperandTable[] = {\n";
- for (auto &Op : OperandTable) {
+ OS << "static constexpr uint8_t OperandTable[] = {\n";
----------------
MaskRay wrote:
namespace-scope constexpr implies internal linkage. You don't need `static`
https://github.com/llvm/llvm-project/pull/135992
More information about the llvm-commits
mailing list