-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Upstream Exception Attr in CallOp #164964
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -708,6 +708,12 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, | |
| mlir::FlatSymbolRefAttr calleeAttr; | ||
| llvm::ArrayRef<mlir::Type> allResultTypes; | ||
|
|
||
| bool hasExceptions = false; | ||
| if (mlir::succeeded(parser.parseOptionalKeyword("exception"))) { | ||
| result.addAttribute("exception", parser.getBuilder().getUnitAttr()); | ||
| hasExceptions = true; | ||
| } | ||
|
|
||
| // If we cannot parse a string callee, it means this is an indirect call. | ||
| if (!parser | ||
| .parseOptionalAttribute(calleeAttr, CIRDialect::getCalleeAttrName(), | ||
|
|
@@ -729,9 +735,15 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, | |
| if (parser.parseRParen()) | ||
| return mlir::failure(); | ||
|
|
||
| if (parser.parseOptionalKeyword("nothrow").succeeded()) | ||
| llvm::SMLoc optionalNothrowLoc = parser.getCurrentLocation(); | ||
| if (parser.parseOptionalKeyword("nothrow").succeeded()) { | ||
| if (hasExceptions) | ||
| return parser.emitError( | ||
| optionalNothrowLoc, | ||
| "should have either `exception` or `nothrow`, but not both"); | ||
|
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. It's not clear to me why we need both of these. Can we not just assume that the absence of 'nothrow' means 'maythrow'? 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. I think yes, this attribute was used as a marker to mark CallOp as invoked, and in TryOp, we convert it to TryCallOp, but I think we can use the absence of In the incubator to 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. (a) One tradeoff here is having to 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.
In FlattenCGF, we convert a call with 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. This is expected (given those are are the LLVM equivalents of call/invoke - I agree the existing names are a bit convoluted), but my point is that if the call is not tagged prior to flatten, you don't know which one to lower to during flattening, because relying on the surrounding cir.try won't be enough. |
||
| result.addAttribute(CIRDialect::getNoThrowAttrName(), | ||
| mlir::UnitAttr::get(parser.getContext())); | ||
| } | ||
|
|
||
| if (parser.parseOptionalKeyword("side_effect").succeeded()) { | ||
| if (parser.parseLParen().failed()) | ||
|
|
@@ -767,13 +779,16 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, | |
| static void printCallCommon(mlir::Operation *op, | ||
| mlir::FlatSymbolRefAttr calleeSym, | ||
| mlir::Value indirectCallee, | ||
| mlir::OpAsmPrinter &printer, bool isNothrow, | ||
| cir::SideEffect sideEffect) { | ||
| mlir::OpAsmPrinter &printer, bool exception, | ||
| bool isNothrow, cir::SideEffect sideEffect) { | ||
| printer << ' '; | ||
|
|
||
| auto callLikeOp = mlir::cast<cir::CIRCallOpInterface>(op); | ||
| auto ops = callLikeOp.getArgOperands(); | ||
|
|
||
| if (exception) | ||
| printer << "exception "; | ||
|
|
||
| if (calleeSym) { | ||
| // Direct calls | ||
| printer.printAttributeWithoutType(calleeSym); | ||
|
|
@@ -793,10 +808,10 @@ static void printCallCommon(mlir::Operation *op, | |
| printer << ")"; | ||
| } | ||
|
|
||
| printer.printOptionalAttrDict(op->getAttrs(), | ||
| {CIRDialect::getCalleeAttrName(), | ||
| CIRDialect::getNoThrowAttrName(), | ||
| CIRDialect::getSideEffectAttrName()}); | ||
| llvm::SmallVector<::llvm::StringRef, 4> elidedAttrs = { | ||
| CIRDialect::getCalleeAttrName(), CIRDialect::getNoThrowAttrName(), | ||
| CIRDialect::getSideEffectAttrName(), CIRDialect::getExceptionAttrName()}; | ||
| printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs); | ||
|
|
||
| printer << " : "; | ||
| printer.printFunctionalType(op->getOperands().getTypes(), | ||
|
|
@@ -811,8 +826,8 @@ mlir::ParseResult cir::CallOp::parse(mlir::OpAsmParser &parser, | |
| void cir::CallOp::print(mlir::OpAsmPrinter &p) { | ||
| mlir::Value indirectCallee = isIndirect() ? getIndirectCall() : nullptr; | ||
| cir::SideEffect sideEffect = getSideEffect(); | ||
| printCallCommon(*this, getCalleeAttr(), indirectCallee, p, getNothrow(), | ||
| sideEffect); | ||
| printCallCommon(*this, getCalleeAttr(), indirectCallee, p, getException(), | ||
| getNothrow(), sideEffect); | ||
| } | ||
|
|
||
| static LogicalResult | ||
|
|
||
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 don't really like this name. I think "mayThrow" would be better, and it aligns with LLVM IR function attribute flag of the same name.
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.
Yea, the existing name might not convey much more information indeed!