-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[TableGen][Decoder] Simplify parseFixedLenOperands (NFCI) #156181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
s-barannikov
merged 1 commit into
llvm:main
from
s-barannikov:tablegen/decoder/simplify-parse-fixed-operands
Aug 30, 2025
Merged
[TableGen][Decoder] Simplify parseFixedLenOperands (NFCI) #156181
s-barannikov
merged 1 commit into
llvm:main
from
s-barannikov:tablegen/decoder/simplify-parse-fixed-operands
Aug 30, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-tablegen Author: Sergei Barannikov (s-barannikov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/156181.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index f1db0368d0988..98569abfbb1a4 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1937,19 +1937,6 @@ static void addOneOperandFields(const Record *EncodingDef, const BitsInit &Bits,
}
void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
- const Record &Def = *Inst->TheDef;
-
- // Gather the outputs/inputs of the instruction, so we can find their
- // positions in the encoding. This assumes for now that they appear in the
- // MCInst in the order that they're listed.
- std::vector<std::pair<const Init *, StringRef>> InOutOperands;
- const DagInit *Out = Def.getValueAsDag("OutOperandList");
- const DagInit *In = Def.getValueAsDag("InOperandList");
- for (const auto &[Idx, Arg] : enumerate(Out->getArgs()))
- InOutOperands.emplace_back(Arg, Out->getArgNameStr(Idx));
- for (const auto &[Idx, Arg] : enumerate(In->getArgs()))
- InOutOperands.emplace_back(Arg, In->getArgNameStr(Idx));
-
// Search for tied operands, so that we can correctly instantiate
// operands that are not explicitly represented in the encoding.
std::map<StringRef, StringRef> TiedNames;
@@ -1972,48 +1959,28 @@ void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
}
// For each operand, see if we can figure out where it is encoded.
- for (const auto &Op : InOutOperands) {
- const Init *OpInit = Op.first;
- StringRef OpName = Op.second;
-
- // We're ready to find the instruction encoding locations for this
- // operand.
-
- // First, find the operand type ("OpInit"), and sub-op names
- // ("SubArgDag") if present.
- const DagInit *SubArgDag = dyn_cast<DagInit>(OpInit);
- if (SubArgDag)
- OpInit = SubArgDag->getOperator();
- const Record *OpTypeRec = cast<DefInit>(OpInit)->getDef();
- // Lookup the sub-operands from the operand type record (note that only
- // Operand subclasses have MIOperandInfo, see CodeGenInstruction.cpp).
- const DagInit *SubOps = OpTypeRec->isSubClassOf("Operand")
- ? OpTypeRec->getValueAsDag("MIOperandInfo")
- : nullptr;
-
+ for (const CGIOperandList::OperandInfo &Op : Inst->Operands) {
// Lookup the decoder method and construct a new OperandInfo to hold our
// result.
- OperandInfo OpInfo = getOpInfo(OpTypeRec);
+ OperandInfo OpInfo = getOpInfo(Op.Rec);
// If we have named sub-operands...
- if (SubArgDag) {
+ if (Op.MIOperandInfo && !Op.SubOpNames[0].empty()) {
// Then there should not be a custom decoder specified on the top-level
// type.
if (!OpInfo.Decoder.empty()) {
PrintError(EncodingDef,
- "DecoderEmitter: operand \"" + OpName + "\" has type \"" +
- OpInit->getAsString() +
+ "DecoderEmitter: operand \"" + Op.Name + "\" has type \"" +
+ Op.Rec->getName() +
"\" with a custom DecoderMethod, but also named "
"sub-operands.");
continue;
}
// Decode each of the sub-ops separately.
- assert(SubOps && SubArgDag->getNumArgs() == SubOps->getNumArgs());
- for (const auto &[I, Arg] : enumerate(SubOps->getArgs())) {
- StringRef SubOpName = SubArgDag->getArgNameStr(I);
- OperandInfo SubOpInfo = getOpInfo(cast<DefInit>(Arg)->getDef());
-
+ for (auto [SubOpName, SubOp] :
+ zip_equal(Op.SubOpNames, Op.MIOperandInfo->getArgs())) {
+ OperandInfo SubOpInfo = getOpInfo(cast<DefInit>(SubOp)->getDef());
addOneOperandFields(EncodingDef, Bits, TiedNames, SubOpName, SubOpInfo);
Operands.push_back(std::move(SubOpInfo));
}
@@ -2022,17 +1989,18 @@ void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
// Otherwise, if we have an operand with sub-operands, but they aren't
// named...
- if (SubOps && OpInfo.Decoder.empty()) {
+ if (Op.MIOperandInfo && OpInfo.Decoder.empty()) {
// If it's a single sub-operand, and no custom decoder, use the decoder
// from the one sub-operand.
- if (SubOps->getNumArgs() == 1)
- OpInfo = getOpInfo(cast<DefInit>(SubOps->getArg(0))->getDef());
+ if (Op.MIOperandInfo->getNumArgs() == 1)
+ OpInfo =
+ getOpInfo(cast<DefInit>(Op.MIOperandInfo->getArg(0))->getDef());
// If we have multiple sub-ops, there'd better have a custom
// decoder. (Otherwise we don't know how to populate them properly...)
- if (SubOps->getNumArgs() > 1) {
+ if (Op.MIOperandInfo->getNumArgs() > 1) {
PrintError(EncodingDef,
- "DecoderEmitter: operand \"" + OpName +
+ "DecoderEmitter: operand \"" + Op.Name +
"\" uses MIOperandInfo with multiple ops, but doesn't "
"have a custom decoder!");
debugDumpRecord(*EncodingDef);
@@ -2040,7 +2008,7 @@ void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
}
}
- addOneOperandFields(EncodingDef, Bits, TiedNames, OpName, OpInfo);
+ addOneOperandFields(EncodingDef, Bits, TiedNames, Op.Name, OpInfo);
// FIXME: it should be an error not to find a definition for a given
// operand, rather than just failing to add it to the resulting
// instruction! (This is a longstanding bug, which will be addressed in an
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/21990 Here is the relevant piece of the build log for the reference
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use information from CGIOperandList instead of re-parsing operand dags from scratch.