[llvm] [TableGen][DecoderEmitter] Add option to emit type-specialized `decodeToMCInst` (PR #146593)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 20:02:29 PDT 2025
================
@@ -2537,6 +2559,67 @@ handleHwModesUnrelatedEncodings(const CodeGenInstruction *Instr,
break;
}
}
+SmallVector<NonTemplatedInsnType>
+DecoderEmitter::parseNonTemplatedInsnTypes(BitwidthSet &InstrBitwidths) {
+ SmallVector<NonTemplatedInsnType> Parsed;
+
+ const Record *InstructionSet = Target.getInstructionSet();
+ std::vector<StringRef> InsnCPPTypes =
+ InstructionSet->getValueAsListOfStrings("InsnCPPTypes");
+
+ if (InsnCPPTypes.empty()) {
+ // If no `InsnCPPTypes` is specified in the instruction info,
+ // create a type-spec with empty values, which will trigger generation of
+ // a templated `decodeToMCInst`.
+ Parsed.emplace_back();
+ return Parsed;
+ }
+
+ // Use field locations for error reporting.
+ SMLoc CPPTypesLoc = InstructionSet->getFieldLoc("InsnCPPTypes");
+ SMLoc BitwidthsLoc = InstructionSet->getFieldLoc("InsnBitwidths");
+
+ const ListInit *InsnBitwidths =
+ InstructionSet->getValueAsListInit("InsnBitwidths");
+
+ Parsed.reserve(InsnCPPTypes.size());
+ BitwidthSet OptionBitwidths;
+
+ for (const auto &[CPPType, BWL] :
+ zip_equal(InsnCPPTypes, InsnBitwidths->getElements())) {
+ BitwidthSet Bitwidths;
+ if (CPPType.empty())
+ PrintFatalError(CPPTypesLoc,
+ "CPP Type cannot be empty in `InsnCPPTypes`");
+ const auto *BitwidthList = dyn_cast<ListInit>(BWL);
+ if (!BitwidthList || BitwidthList->empty())
+ PrintFatalError(BitwidthsLoc,
+ "No bitwidths specified for InsnCPPType : " + CPPType);
+
+ for (int64_t Bitwidth : BitwidthList->getAsListOfInts()) {
+ if (!OptionBitwidths.insert(Bitwidth).second)
+ PrintFatalError(BitwidthsLoc,
+ "Bitwidth " + Twine(Bitwidth) + " already specified.");
+
+ if (!InstrBitwidths.contains(Bitwidth))
+ PrintFatalError(BitwidthsLoc, "No instruction of bitwidth " +
+ Twine(Bitwidth) + " supported.");
+ InstrBitwidths.erase(Bitwidth);
+ Bitwidths.insert(Bitwidth);
+ }
+ Parsed.emplace_back(NonTemplatedInsnType{CPPType, Bitwidths});
----------------
jurahul wrote:
It gave a compiler error when I tried, but I have addressed it now by adding a constructor to the struct.
https://github.com/llvm/llvm-project/pull/146593
More information about the llvm-commits
mailing list