-
Notifications
You must be signed in to change notification settings - Fork 118
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
Implement pretty printing for SelectOp, ClampOp, AfterAllOp types. Clean up type prints. #37
Conversation
218cfd7
to
4802e97
Compare
SmallVectorImpl<OpAsmParser::UnresolvedOperand>& operands, | ||
SmallVectorImpl<Type>& opTypes, Type& result) { | ||
// Insert a type for each operand. Need to do this since passing the type of | ||
// a variadic op gives no indication of how many operands were provided. |
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.
Oof this is unfortunate. Let me take a closer look at this during the next pass over this PR. I'll submit my review for now because there's already plenty of comments to address.
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.
I've been staring at how this function creates a temporary vector of pointers and realized that reuse is probably overrated in this case. Then I rewrote this function without leveraging parseSameOperandsAndResultTypeImpl
, and I think I like the result better:
ParseResult parseVariadicSameOperandsAndResultType(
OpAsmParser& parser,
SmallVectorImpl<OpAsmParser::UnresolvedOperand>& operands,
SmallVectorImpl<Type>& opTypes, Type& result) {
llvm::SMLoc loc = parser.getCurrentLocation();
Type type;
if (parser.parseType(type)) {
return failure();
}
// Handle if function type, all operand types did not match result type.
if (auto fnType = type.dyn_cast<FunctionType>()) {
if (fnType.getResults().size() != 1) {
return parser.emitError(loc, "expected single output");
}
llvm::append_range(opTypes, fnType.getInputs());
result = fnType.getResults()[0];
return success();
}
// Handle bare types. ` : type` indicating all input/output types match.
opTypes.append(operands.size(), type);
result = type;
return success();
}
Yes, there is some duplication with parseSameOperandsAndResultTypeImpl
(more precisely, the parseType and dyn_cast and fnType.getResults().size() != 1 parts), but I think this version of code is easier to understand. What's yout take on this?
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.
Hmm.. So the real advantage of reuse in printer/parser code in my opinion is the parity:
let x = printSameOperandsAndResultTypeImpl(input)
let y = parseSameOperandsAndResultTypeImpl(x)
assert(y == input)
I feel like there is extra gravity to code duplication in printer/parser code. Duplicating this code adds the overhead of "if we change anything about the printer code, we need to update the parser code in two places." I'll keep thinking on how to improve this.
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.
Looks like I clicked "Comment" in my previous review, instead of "Request changes".
4802e97
to
a7838fb
Compare
a7838fb
to
b5f42e2
Compare
Use SameOperandsAndResultType for operations that may have single type (ClampOp, AfterAllOp).
b5f42e2
to
a5718ab
Compare
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 466802406
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 484271777
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 484271777
…shapeOp, ComputeReshapeShapeOp, SelectOp. Based on: openxla/stablehlo#37 PiperOrigin-RevId: 484271777
Pretty print for SelectOp based on vector display of
arith.select
: https://mlir.llvm.org/docs/Dialects/ArithmeticOps/#arithselect-mlirarithselectopNote that if branch types do not match exactly,
functional-type
is used:Now that
SameOperandsAndResultType
is merged into main, we can use it in other ops that may have the same operands and result types like ClampOp, or ops that must have matching types like AfterAllOp:Added print tests and invalid MLIR tests.
Additionally this change cleans up some type prints, removing parentheses around operands / including parens around inputs in type printing for consistency with the rest of the dialect's assembly: