MLIR  20.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 
16 #include "mlir/Support/LLVM.h"
17 #include "llvm/ADT/STLExtras.h"
18 
19 namespace mlir {
20 
21 // Forward declarations.
22 class BranchOpInterface;
23 class ConversionTarget;
24 class MLIRContext;
25 class Operation;
26 class TypeConverter;
27 class 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.
31 void 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.
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.
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.
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.
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`.
71 } // namespace mlir
72 
73 #endif // MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Type conversion class.
Include the generated interface declarations.
bool isLegalForReturnOpTypeConversionPattern(Operation *op, const TypeConverter &converter, bool returnOpAlwaysLegal=false)
For ReturnLike ops (except return), return True.
bool isNotBranchOpInterfaceOrReturnLikeOp(Operation *op)
Return true if op is neither BranchOpInterface nor ReturnLike.
const FrozenRewritePatternSet & patterns
void populateBranchOpInterfaceTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, function_ref< bool(BranchOpInterface branchOp, int idx)> shouldConvertBranchOperand=nullptr)
Add a pattern to the given pattern list to rewrite branch operations to use operands that have been l...
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter)
Add a pattern to the given pattern list to convert the operand and result types of a CallOp with the ...
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter)
Add a pattern to the given pattern list to rewrite return ops to use operands that have been legalize...
bool isLegalForBranchOpInterfaceTypeConversionPattern(Operation *op, const TypeConverter &converter)
Return true if op is a BranchOpInterface op whose operands are all legal according to converter.