[clang] [CIR] Lower cir.construct_catch_param on Itanium (PR #195904)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu May 7 10:17:03 PDT 2026
================
@@ -0,0 +1,75 @@
+//===- CIRTransformUtils.cpp - Shared helpers for CIR transforms ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CIRTransformUtils.h"
+
+#include "clang/CIR/Dialect/IR/CIRTypes.h"
+
+mlir::Block *cir::replaceCallWithTryCall(cir::CallOp callOp,
+ mlir::Block *unwindDest,
+ mlir::Location loc,
+ mlir::RewriterBase &rewriter) {
+ mlir::Block *callBlock = callOp->getBlock();
+
+ assert(!callOp.getNothrow() && "call is not expected to throw");
+
+ // Split the block after the call - remaining ops become the normal
+ // destination.
+ mlir::Block *normalDest =
+ rewriter.splitBlock(callBlock, std::next(callOp->getIterator()));
+
+ // Build the try_call to replace the original call.
+ rewriter.setInsertionPoint(callOp);
+ cir::TryCallOp tryCallOp;
+ if (callOp.isIndirect()) {
+ mlir::Value indTarget = callOp.getIndirectCall();
+ auto ptrTy = mlir::cast<cir::PointerType>(indTarget.getType());
+ auto resTy = mlir::cast<cir::FuncType>(ptrTy.getPointee());
+ tryCallOp =
+ cir::TryCallOp::create(rewriter, loc, indTarget, resTy, normalDest,
+ unwindDest, callOp.getArgOperands());
+ } else {
+ mlir::Type resType = callOp->getNumResults() > 0
+ ? callOp->getResult(0).getType()
+ : mlir::Type();
+ tryCallOp =
+ cir::TryCallOp::create(rewriter, loc, callOp.getCalleeAttr(), resType,
+ normalDest, unwindDest, callOp.getArgOperands());
+ }
+
+ // Copy all attributes from the original call except those already set by
+ // TryCallOp::create or that are operation-specific and should not be copied.
+ llvm::StringRef excludedAttrs[] = {
+ cir::CIRDialect::getCalleeAttrName(), // Set by create()
+ cir::CIRDialect::getOperandSegmentSizesAttrName(),
+ };
+#ifndef NDEBUG
+ // We don't expect to ever see any of these attributes on a call that we
+ // converted to a try_call.
+ llvm::StringRef unexpectedAttrs[] = {
----------------
erichkeane wrote:
Do we expect this list to get large? If not,perahps it should just be an init-list inside the assert?
https://github.com/llvm/llvm-project/pull/195904
More information about the cfe-commits
mailing list