MLIR 22.0.0git
FuncConversions.h
Go to the documentation of this file.
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
17#include "mlir/Support/LLVM.h"
18#include "llvm/ADT/STLExtras.h"
19
20namespace mlir {
21
22// Forward declarations.
23class BranchOpInterface;
24class ConversionTarget;
25class MLIRContext;
26class Operation;
27class TypeConverter;
29
30/// Add a pattern to the given pattern list to convert the operand and result
31/// types of a CallOp with the given type converter.
33 const TypeConverter &converter,
34 PatternBenefit benefit = 1);
35
36/// Add a pattern to the given pattern list to rewrite branch operations to use
37/// operands that have been legalized by the conversion framework. This can only
38/// be done if the branch operation implements the BranchOpInterface. Only
39/// needed for partial conversions.
40///
41/// If for some branch ops, we need to convert/legalize only a sub-set of the
42/// op's operands, such filtering behavior can be specified in
43/// shouldConvertBranchOperand. This callback should return true if branchOp's
44/// operand at index idx should be converted.
46 RewritePatternSet &patterns, const TypeConverter &converter,
47 function_ref<bool(BranchOpInterface branchOp, int idx)>
48 shouldConvertBranchOperand = nullptr,
49 PatternBenefit benefit = 1);
50
51/// Return true if op is a BranchOpInterface op whose operands are all legal
52/// according to converter.
54 Operation *op, const TypeConverter &converter);
55
56/// Add a pattern to the given pattern list to rewrite `return` ops to use
57/// operands that have been legalized by the conversion framework.
59 const TypeConverter &converter,
60 PatternBenefit benefit = 1);
61
62/// For ReturnLike ops (except `return`), return True. If op is a `return` &&
63/// returnOpAlwaysLegal is false, legalize op according to converter. Otherwise,
64/// return false.
66 const TypeConverter &converter,
67 bool returnOpAlwaysLegal = false);
68
69/// Return true if op is neither BranchOpInterface nor ReturnLike.
70///
71/// TODO Try to get rid of this function and invert the meaning of
72/// `isLegalForBranchOpInterfaceTypeConversionPattern` and
73/// `isLegalForReturnOpTypeConversionPattern`.
75} // namespace mlir
76
77#endif // MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
Include the generated interface declarations.
bool isLegalForReturnOpTypeConversionPattern(Operation *op, const TypeConverter &converter, bool returnOpAlwaysLegal=false)
For ReturnLike ops (except return), return True.
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, PatternBenefit benefit=1)
Add a pattern to the given pattern list to rewrite return ops to use operands that have been legalize...
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, PatternBenefit benefit=1)
Add a pattern to the given pattern list to convert the operand and result types of a CallOp with the ...
bool isNotBranchOpInterfaceOrReturnLikeOp(Operation *op)
Return true if op is neither BranchOpInterface nor ReturnLike.
void populateBranchOpInterfaceTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, function_ref< bool(BranchOpInterface branchOp, int idx)> shouldConvertBranchOperand=nullptr, PatternBenefit benefit=1)
Add a pattern to the given pattern list to rewrite branch operations to use operands that have been l...
const FrozenRewritePatternSet & patterns
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152
bool isLegalForBranchOpInterfaceTypeConversionPattern(Operation *op, const TypeConverter &converter)
Return true if op is a BranchOpInterface op whose operands are all legal according to converter.