1//===- FuncConversions.h - Patterns for converting func.func ----*- 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// This files contains patterns for converting functions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
14#define MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
15
16#include "mlir/Support/LLVM.h"
17#include "llvm/ADT/STLExtras.h"
18
19namespace mlir {
20
21// Forward declarations.
22class BranchOpInterface;
23class ConversionTarget;
24class MLIRContext;
25class Operation;
26class TypeConverter;
27class RewritePatternSet;
28
29/// Add a pattern to the given pattern list to convert the operand and result
30/// types of a CallOp with the given type converter.
31void populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
32 const TypeConverter &converter);
33
34/// Add a pattern to the given pattern list to rewrite branch operations to use
35/// operands that have been legalized by the conversion framework. This can only
36/// be done if the branch operation implements the BranchOpInterface. Only
37/// needed for partial conversions.
38///
39/// If for some branch ops, we need to convert/legalize only a sub-set of the
40/// op's operands, such filtering behavior can be specified in
41/// shouldConvertBranchOperand. This callback should return true if branchOp's
42/// operand at index idx should be converted.
43void populateBranchOpInterfaceTypeConversionPattern(
44 RewritePatternSet &patterns, const TypeConverter &converter,
45 function_ref<bool(BranchOpInterface branchOp, int idx)>
46 shouldConvertBranchOperand = nullptr);
47
48/// Return true if op is a BranchOpInterface op whose operands are all legal
49/// according to converter.
50bool isLegalForBranchOpInterfaceTypeConversionPattern(
51 Operation *op, const TypeConverter &converter);
52
53/// Add a pattern to the given pattern list to rewrite `return` ops to use
54/// operands that have been legalized by the conversion framework.
55void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns,
56 const TypeConverter &converter);
57
58/// For ReturnLike ops (except `return`), return True. If op is a `return` &&
59/// returnOpAlwaysLegal is false, legalize op according to converter. Otherwise,
60/// return false.
61bool isLegalForReturnOpTypeConversionPattern(Operation *op,
62 const TypeConverter &converter,
63 bool returnOpAlwaysLegal = false);
64
65/// Return true if op is neither BranchOpInterface nor ReturnLike.
66///
67/// TODO Try to get rid of this function and invert the meaning of
68/// `isLegalForBranchOpInterfaceTypeConversionPattern` and
69/// `isLegalForReturnOpTypeConversionPattern`.
70bool isNotBranchOpInterfaceOrReturnLikeOp(Operation *op);
71} // namespace mlir
72
73#endif // MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
74

source code of mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h