@@ -721,8 +721,28 @@ unsigned cir::CallOp::getNumArgOperands() {
721721 return this ->getOperation ()->getNumOperands ();
722722}
723723
724+ static mlir::ParseResult
725+ parseTryCallDestinations (mlir::OpAsmParser &parser,
726+ mlir::OperationState &result) {
727+ mlir::Block *normalDestSuccessor;
728+ if (parser.parseSuccessor (normalDestSuccessor))
729+ return mlir::failure ();
730+
731+ if (parser.parseComma ())
732+ return mlir::failure ();
733+
734+ mlir::Block *unwindDestSuccessor;
735+ if (parser.parseSuccessor (unwindDestSuccessor))
736+ return mlir::failure ();
737+
738+ result.addSuccessors (normalDestSuccessor);
739+ result.addSuccessors (unwindDestSuccessor);
740+ return mlir::success ();
741+ }
742+
724743static mlir::ParseResult parseCallCommon (mlir::OpAsmParser &parser,
725- mlir::OperationState &result) {
744+ mlir::OperationState &result,
745+ bool hasDestinationBlocks = false ) {
726746 llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand, 4 > ops;
727747 llvm::SMLoc opsLoc;
728748 mlir::FlatSymbolRefAttr calleeAttr;
@@ -749,6 +769,11 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser,
749769 if (parser.parseRParen ())
750770 return mlir::failure ();
751771
772+ if (hasDestinationBlocks &&
773+ parseTryCallDestinations (parser, result).failed ()) {
774+ return ::mlir::failure ();
775+ }
776+
752777 if (parser.parseOptionalKeyword (" nothrow" ).succeeded ())
753778 result.addAttribute (CIRDialect::getNoThrowAttrName (),
754779 mlir::UnitAttr::get (parser.getContext ()));
@@ -788,7 +813,9 @@ static void printCallCommon(mlir::Operation *op,
788813 mlir::FlatSymbolRefAttr calleeSym,
789814 mlir::Value indirectCallee,
790815 mlir::OpAsmPrinter &printer, bool isNothrow,
791- cir::SideEffect sideEffect) {
816+ cir::SideEffect sideEffect,
817+ mlir::Block *normalDest = nullptr ,
818+ mlir::Block *unwindDest = nullptr ) {
792819 printer << ' ' ;
793820
794821 auto callLikeOp = mlir::cast<cir::CIRCallOpInterface>(op);
@@ -802,8 +829,18 @@ static void printCallCommon(mlir::Operation *op,
802829 assert (indirectCallee);
803830 printer << indirectCallee;
804831 }
832+
805833 printer << " (" << ops << " )" ;
806834
835+ if (normalDest) {
836+ assert (unwindDest && " expected two successors" );
837+ auto tryCall = cast<cir::TryCallOp>(op);
838+ printer << ' ' << tryCall.getNormalDest ();
839+ printer << " ," ;
840+ printer << ' ' ;
841+ printer << tryCall.getUnwindDest ();
842+ }
843+
807844 if (isNothrow)
808845 printer << " nothrow" ;
809846
@@ -813,11 +850,11 @@ static void printCallCommon(mlir::Operation *op,
813850 printer << " )" ;
814851 }
815852
816- printer. printOptionalAttrDict (op-> getAttrs (),
817- { CIRDialect::getCalleeAttrName (),
818- CIRDialect::getNoThrowAttrName (),
819- CIRDialect::getSideEffectAttrName ()}) ;
820-
853+ llvm::SmallVector<::llvm::StringRef> elidedAttrs = {
854+ CIRDialect::getCalleeAttrName (), CIRDialect::getNoThrowAttrName (),
855+ CIRDialect::getSideEffectAttrName (),
856+ CIRDialect::getOperandSegmentSizesAttrName ()};
857+ printer. printOptionalAttrDict (op-> getAttrs (), elidedAttrs);
821858 printer << " : " ;
822859 printer.printFunctionalType (op->getOperands ().getTypes (),
823860 op->getResultTypes ());
@@ -898,6 +935,59 @@ cir::CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
898935 return verifyCallCommInSymbolUses (*this , symbolTable);
899936}
900937
938+ // ===----------------------------------------------------------------------===//
939+ // TryCallOp
940+ // ===----------------------------------------------------------------------===//
941+
942+ mlir::OperandRange cir::TryCallOp::getArgOperands () {
943+ if (isIndirect ())
944+ return getArgs ().drop_front (1 );
945+ return getArgs ();
946+ }
947+
948+ mlir::MutableOperandRange cir::TryCallOp::getArgOperandsMutable () {
949+ mlir::MutableOperandRange args = getArgsMutable ();
950+ if (isIndirect ())
951+ return args.slice (1 , args.size () - 1 );
952+ return args;
953+ }
954+
955+ mlir::Value cir::TryCallOp::getIndirectCall () {
956+ assert (isIndirect ());
957+ return getOperand (0 );
958+ }
959+
960+ // / Return the operand at index 'i'.
961+ Value cir::TryCallOp::getArgOperand (unsigned i) {
962+ if (isIndirect ())
963+ ++i;
964+ return getOperand (i);
965+ }
966+
967+ // / Return the number of operands.
968+ unsigned cir::TryCallOp::getNumArgOperands () {
969+ if (isIndirect ())
970+ return this ->getOperation ()->getNumOperands () - 1 ;
971+ return this ->getOperation ()->getNumOperands ();
972+ }
973+
974+ LogicalResult
975+ cir::TryCallOp::verifySymbolUses (SymbolTableCollection &symbolTable) {
976+ return verifyCallCommInSymbolUses (*this , symbolTable);
977+ }
978+
979+ mlir::ParseResult cir::TryCallOp::parse (mlir::OpAsmParser &parser,
980+ mlir::OperationState &result) {
981+ return parseCallCommon (parser, result, /* hasDestinationBlocks=*/ true );
982+ }
983+
984+ void cir::TryCallOp::print (::mlir::OpAsmPrinter &p) {
985+ mlir::Value indirectCallee = isIndirect () ? getIndirectCall () : nullptr ;
986+ cir::SideEffect sideEffect = getSideEffect ();
987+ printCallCommon (*this , getCalleeAttr (), indirectCallee, p, getNothrow (),
988+ sideEffect, getNormalDest (), getUnwindDest ());
989+ }
990+
901991// ===----------------------------------------------------------------------===//
902992// ReturnOp
903993// ===----------------------------------------------------------------------===//
0 commit comments