clang 23.0.0git
CIRTransformUtils.h
Go to the documentation of this file.
1//===- CIRTransformUtils.h - Shared helpers for CIR transforms -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_CIR_DIALECT_TRANSFORMS_CIRTRANSFORMUTILS_H
10#define LLVM_CLANG_CIR_DIALECT_TRANSFORMS_CIRTRANSFORMUTILS_H
11
12#include "mlir/IR/Location.h"
13#include "mlir/IR/PatternMatch.h"
15
16#include "llvm/ADT/SmallVector.h"
17
18namespace cir {
19
20/// Replace a `cir::CallOp` with a `cir::TryCallOp` whose unwind destination
21/// is \p unwindDest. The call's parent block is split immediately after the
22/// call; the resulting suffix block becomes the try_call's normal
23/// destination and is returned to the caller.
24///
25/// All attributes of the original call other than the callee and operand
26/// segment sizes (which `TryCallOp::create` sets itself) are copied onto
27/// the new try_call. Uses of the original call's result, if any, are
28/// redirected to the try_call's result, and the original call is erased.
29///
30/// The call must not already be marked nothrow.
31mlir::Block *replaceCallWithTryCall(cir::CallOp callOp, mlir::Block *unwindDest,
32 mlir::Location loc,
33 mlir::RewriterBase &rewriter);
34
35/// Replace a `cir::ThrowOp` with a `cir::TryThrowOp` whose unwind
36/// destination is \p unwindDest. The throw's parent block is split
37/// immediately after the throw; the resulting suffix block (which should
38/// contain the `cir.unreachable` that follows every throw) becomes the
39/// try_throw's normal destination and is returned to the caller.
40///
41/// All attributes of the original throw other than the operand segment
42/// sizes (which `TryThrowOp::create` sets itself) are copied onto the new
43/// try_throw, and the original throw is erased.
44mlir::Block *replaceThrowWithTryThrow(cir::ThrowOp throwOp,
45 mlir::Block *unwindDest,
46 mlir::Location loc,
47 mlir::RewriterBase &rewriter);
48
49/// Collect ops in blocks that are unreachable from their region's entry,
50/// appending them to \p ops. Used by CIR passes that drive
51/// `applyPartialConversion` and need to feed it operations the conversion
52/// driver's dominance-order traversal would otherwise skip.
53void collectUnreachable(mlir::Operation *parent,
54 llvm::SmallVectorImpl<mlir::Operation *> &ops);
55
56} // namespace cir
57
58#endif // LLVM_CLANG_CIR_DIALECT_TRANSFORMS_CIRTRANSFORMUTILS_H
void collectUnreachable(mlir::Operation *parent, llvm::SmallVectorImpl< mlir::Operation * > &ops)
Collect ops in blocks that are unreachable from their region's entry, appending them to ops.
mlir::Block * replaceThrowWithTryThrow(cir::ThrowOp throwOp, mlir::Block *unwindDest, mlir::Location loc, mlir::RewriterBase &rewriter)
Replace a cir::ThrowOp with a cir::TryThrowOp whose unwind destination is unwindDest.
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.