-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][ODS] Fix default inferReturnTypes generation for variadic operands #131483
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
Open
Groverkss
wants to merge
3
commits into
llvm:main
Choose a base branch
from
Groverkss:fix-ods-variadic-infer-return-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2641,8 +2641,7 @@ void OpEmitter::genSeparateArgParamBuilder() { | |
|
||
// Avoid emitting "resultTypes.size() >= 0u" which is always true. | ||
if (!hasVariadicResult || numNonVariadicResults != 0) | ||
body << " " | ||
<< "assert(resultTypes.size() " | ||
body << " " << "assert(resultTypes.size() " | ||
<< (hasVariadicResult ? ">=" : "==") << " " | ||
<< numNonVariadicResults | ||
<< "u && \"mismatched number of results\");\n"; | ||
|
@@ -3751,29 +3750,15 @@ void OpEmitter::genTypeInterfaceMethods() { | |
fctx.addSubst("_ctxt", "context"); | ||
body << " ::mlir::Builder odsBuilder(context);\n"; | ||
|
||
// Preprocessing stage to verify all accesses to operands are valid. | ||
int maxAccessedIndex = -1; | ||
for (int i = 0, e = op.getNumResults(); i != e; ++i) { | ||
const InferredResultType &infer = op.getInferredResultType(i); | ||
if (!infer.isArg()) | ||
continue; | ||
Operator::OperandOrAttribute arg = | ||
op.getArgToOperandOrAttribute(infer.getIndex()); | ||
if (arg.kind() == Operator::OperandOrAttribute::Kind::Operand) { | ||
maxAccessedIndex = | ||
std::max(maxAccessedIndex, arg.operandOrAttributeIndex()); | ||
} | ||
} | ||
if (maxAccessedIndex != -1) { | ||
body << " if (operands.size() <= " << Twine(maxAccessedIndex) << ")\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check now handled in the adaptor? (I don't recall if there is a test for this upstream) |
||
body << " return ::mlir::failure();\n"; | ||
} | ||
// Emit an adaptor to access right ranges for ods operands. | ||
body << " " << op.getCppClassName() | ||
<< "::Adaptor adaptor(operands, attributes, properties, regions);\n"; | ||
|
||
// Process the type inference graph in topological order, starting from types | ||
// that are always fully-inferred: operands and results with constructible | ||
// types. The type inference graph here will always be a DAG, so this gives | ||
// us the correct order for generating the types. -1 is a placeholder to | ||
// indicate the type for a result has not been generated. | ||
// Process the type inference graph in topological order, starting from | ||
// types that are always fully-inferred: operands and results with | ||
// constructible types. The type inference graph here will always be a | ||
// DAG, so this gives us the correct order for generating the types. -1 is | ||
// a placeholder to indicate the type for a result has not been generated. | ||
SmallVector<int> constructedIndices(op.getNumResults(), -1); | ||
int inferredTypeIdx = 0; | ||
for (int numResults = op.getNumResults(); inferredTypeIdx != numResults;) { | ||
|
@@ -3788,10 +3773,11 @@ void OpEmitter::genTypeInterfaceMethods() { | |
Operator::OperandOrAttribute arg = | ||
op.getArgToOperandOrAttribute(infer.getIndex()); | ||
if (arg.kind() == Operator::OperandOrAttribute::Kind::Operand) { | ||
typeStr = ("operands[" + Twine(arg.operandOrAttributeIndex()) + | ||
"].getType()") | ||
.str(); | ||
|
||
std::string getter = | ||
"adaptor." + | ||
op.getGetterName( | ||
op.getOperand(arg.operandOrAttributeIndex()).name); | ||
typeStr = (getter + "().getType()"); | ||
// If this is an attribute, index into the attribute dictionary. | ||
} else { | ||
auto *attr = | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably can remove the second << here and merge the strings, not sure its doing much here (if it were handling indentation other story)