Skip to content

Commit 2658855

Browse files
committed
Specialize decodeInstruction
1 parent 04366ee commit 2658855

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,14 +2261,23 @@ static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
22612261
// emitDecodeInstruction - Emit the templated helper function
22622262
// decodeInstruction().
22632263
static void emitDecodeInstruction(formatted_raw_ostream &OS, bool IsVarLenInst,
2264-
unsigned OpcodeMask) {
2264+
unsigned OpcodeMask,
2265+
StringRef SpecializedInsnType) {
22652266
const bool HasTryDecode = OpcodeMask & ((1 << MCD::OPC_TryDecode) |
22662267
(1 << MCD::OPC_TryDecodeOrFail));
22672268
const bool HasCheckPredicate =
22682269
OpcodeMask &
22692270
((1 << MCD::OPC_CheckPredicate) | (1 << MCD::OPC_CheckPredicateOrFail));
22702271
const bool HasSoftFail = OpcodeMask & (1 << MCD::OPC_SoftFail);
22712272

2273+
auto emitTemplate = [&OS, SpecializedInsnType] {
2274+
if (SpecializedInsnType.empty())
2275+
OS << "template <typename InsnType>\n";
2276+
};
2277+
2278+
StringRef InsnType =
2279+
SpecializedInsnType.empty() ? "InsnType" : SpecializedInsnType;
2280+
22722281
OS << R"(
22732282
static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
22742283
unsigned NumToSkip = *Ptr++;
@@ -2277,11 +2286,13 @@ static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
22772286
if (getNumToSkipInBytes() == 3)
22782287
OS << " NumToSkip |= (*Ptr++) << 16;\n";
22792288
OS << R"( return NumToSkip;
2280-
}
2289+
})";
22812290

2282-
template <typename InsnType>
2283-
static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
2284-
InsnType insn, uint64_t Address,
2291+
emitTemplate();
2292+
OS << R"(
2293+
static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, )";
2294+
OS << InsnType << " insn,\n";
2295+
OS << R"( uint64_t Address,
22852296
const MCDisassembler *DisAsm,
22862297
const MCSubtargetInfo &STI)";
22872298
if (IsVarLenInst) {
@@ -2802,7 +2813,11 @@ namespace {
28022813
emitPredicateFunction(OS, TableInfo.Predicates, indent(0));
28032814

28042815
// Emit the main entry point for the decoder, decodeInstruction().
2805-
emitDecodeInstruction(OS, IsVarLenInst, OpcodeMask);
2816+
// Generate non-templated code if exactly one InsnCPPType was specified.
2817+
StringRef SpecializedInsnType =
2818+
NonTemplatedInsnTypes.size() == 1 ? NonTemplatedInsnTypes[0].CPPType : "";
2819+
2820+
emitDecodeInstruction(OS, IsVarLenInst, OpcodeMask, SpecializedInsnType);
28062821

28072822
OS << "\n} // namespace\n";
28082823
}

0 commit comments

Comments
 (0)