[llvm] [TableGen][DecoderEmitter] Add option to emit type-specialized code (PR #146593)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 17 23:55:35 PDT 2025
================
@@ -2562,53 +2764,143 @@ namespace {
}
}
+ bool GenerateTemplated =
+ Target.getInstructionSet()->getValueAsBit("GenerateTemplatedDecoder");
+
+ // For variable instruction, we emit a instruction length table to let the
+ // decoder know how long the instructions are. You can see example usage in
+ // M68k's disassembler.
+ if (IsVarLenInst) {
+ if (GenerateTemplated)
+ PrintFatalError(
+ "Templated decoder not needed for variable length instruction");
+ emitInstrLenTable(OS, InstrLen);
+ }
+
DecoderTableInfo TableInfo;
+ bool HasCheckPredicate = false;
unsigned OpcodeMask = 0;
- for (const auto &[NSAndByteSize, EncodingIDs] : EncMap) {
- const std::string &DecoderNamespace = NSAndByteSize.first;
- const unsigned BitWidth = 8 * NSAndByteSize.second;
- // Emit the decoder for this namespace+width combination.
- FilterChooser FC(NumberedEncodings, EncodingIDs, Operands,
- IsVarLenInst ? MaxInstLen : BitWidth, this);
-
- // The decode table is cleared for each top level decoder function. The
- // predicates and decoders themselves, however, are shared across all
- // decoders to give more opportunities for uniqueing.
- TableInfo.Table.clear();
- TableInfo.pushScope();
- FC.emitTableEntries(TableInfo);
- // Any NumToSkip fixups in the top level scope can resolve to the
- // OPC_Fail at the end of the table.
- assert(TableInfo.isOutermostScope() && "fixup stack phasing error!");
- TableInfo.popScope();
- TableInfo.Table.push_back(MCD::OPC_Fail);
+ // Helper lambda to emit the decoder code for a given instruction Bitwidth
+ // and associated C++ type. If `Bitwidth` is 0 (and CPPType is empty) it will
+ // generate templated decoder code.
+ auto emitDecoder = [&](const CPPType &Type, StringRef Suffix) {
----------------
s-barannikov wrote:
This should be a function/method.
https://github.com/llvm/llvm-project/pull/146593
More information about the llvm-commits
mailing list