14 mlir::Block *unwindDest,
16 mlir::RewriterBase &rewriter) {
17 mlir::Block *callBlock = callOp->getBlock();
19 assert(!callOp.getNothrow() &&
"call is not expected to throw");
23 mlir::Block *normalDest =
24 rewriter.splitBlock(callBlock, std::next(callOp->getIterator()));
27 rewriter.setInsertionPoint(callOp);
28 cir::TryCallOp tryCallOp;
29 if (callOp.isIndirect()) {
30 mlir::Value indTarget = callOp.getIndirectCall();
31 auto ptrTy = mlir::cast<cir::PointerType>(indTarget.getType());
32 auto resTy = mlir::cast<cir::FuncType>(ptrTy.getPointee());
34 cir::TryCallOp::create(rewriter, loc, indTarget, resTy, normalDest,
35 unwindDest, callOp.getArgOperands());
37 mlir::Type resType = callOp->getNumResults() > 0
38 ? callOp->getResult(0).getType()
41 cir::TryCallOp::create(rewriter, loc, callOp.getCalleeAttr(), resType,
42 normalDest, unwindDest, callOp.getArgOperands());
47 llvm::StringRef excludedAttrs[] = {
48 cir::CIRDialect::getCalleeAttrName(),
49 cir::CIRDialect::getOperandSegmentSizesAttrName(),
51 for (mlir::NamedAttribute attr : callOp->getAttrs()) {
52 if (llvm::is_contained(excludedAttrs, attr.getName()))
54 assert(!llvm::is_contained(
56 cir::CIRDialect::getNoThrowAttrName(),
57 cir::CIRDialect::getNoUnwindAttrName(),
60 "unexpected attribute on converted call");
61 tryCallOp->setAttr(attr.getName(), attr.getValue());
67 if (callOp->getNumResults() > 0)
68 rewriter.replaceAllUsesWith(callOp->getResult(0), tryCallOp.getResult());
70 rewriter.eraseOp(callOp);
mlir::Block * replaceCallWithTryCall(cir::CallOp callOp, mlir::Block *unwindDest, mlir::Location loc, mlir::RewriterBase &rewriter)
Replace a cir::CallOp with a cir::TryCallOp whose unwind destination is unwindDest.