clang 24.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/// Helper type for lowering global ctor/dtors, that contain all the values
20/// needed for transforming the values between IRs.
23 llvm::StringRef associated = "")
25 std::string name;
27 std::string associated;
28};
29
30/// Replace a `cir::CallOp` with a `cir::TryCallOp` whose unwind destination
31/// is \p unwindDest. The call's parent block is split immediately after the
32/// call; the resulting suffix block becomes the try_call's normal
33/// destination and is returned to the caller.
34///
35/// All attributes of the original call other than the callee and operand
36/// segment sizes (which `TryCallOp::create` sets itself) are copied onto
37/// the new try_call. Uses of the original call's result, if any, are
38/// redirected to the try_call's result, and the original call is erased.
39///
40/// The call must not already be marked nothrow.
41mlir::Block *replaceCallWithTryCall(cir::CallOp callOp, mlir::Block *unwindDest,
42 mlir::Location loc,
43 mlir::RewriterBase &rewriter);
44
45/// Replace a `cir::ThrowOp` with a `cir::TryThrowOp` whose unwind
46/// destination is \p unwindDest. The try_throw's normal destination is a new
47/// block, inserted right after the throw's block, that holds only a
48/// `cir.unreachable`; it is returned to the caller. The ops that followed the
49/// throw in its block (typically a `cir.unreachable`) are erased.
50///
51/// All attributes of the original throw other than the operand segment
52/// sizes (which `TryThrowOp::create` sets itself) are copied onto the new
53/// try_throw, and the original throw is erased.
54mlir::Block *replaceThrowWithTryThrow(cir::ThrowOp throwOp,
55 mlir::Block *unwindDest,
56 mlir::Location loc,
57 mlir::RewriterBase &rewriter);
58
59/// Collect ops in blocks that are unreachable from their region's entry,
60/// appending them to \p ops. Used by CIR passes that drive
61/// `applyPartialConversion` and need to feed it operations the conversion
62/// driver's dominance-order traversal would otherwise skip.
63void collectUnreachable(mlir::Operation *parent,
65
66} // namespace cir
67
68#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.
GlobalCtorDtorEntry(llvm::StringRef name, uint32_t priority, llvm::StringRef associated="")