CIRCT  20.0.0git
ConversionPatterns.h
Go to the documentation of this file.
1 //===- ConversionPatterns.h - Common Conversion patterns --------*- 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 CIRCT_SUPPORT_CONVERSIONPATTERNS_H
10 #define CIRCT_SUPPORT_CONVERSIONPATTERNS_H
11 
12 #include "circt/Support/LLVM.h"
13 
14 #include "mlir/Transforms/DialectConversion.h"
15 
16 namespace circt {
17 
18 // Performs type conversion on the given operation.
19 LogicalResult doTypeConversion(Operation *op, ValueRange operands,
20  ConversionPatternRewriter &rewriter,
21  const TypeConverter *typeConverter);
22 
23 /// Generic pattern which replaces an operation by one of the same operation
24 /// name, but with converted attributes, operands, and result types to eliminate
25 /// illegal types. Uses generic builders based on OperationState to make sure
26 /// that this pattern can apply to _any_ operation.
27 ///
28 /// Useful when a conversion can be entirely defined by a TypeConverter.
29 struct TypeConversionPattern : public mlir::ConversionPattern {
30 public:
31  TypeConversionPattern(TypeConverter &converter, MLIRContext *context)
32  : ConversionPattern(converter, MatchAnyOpTypeTag(), 1, context) {}
33  using ConversionPattern::ConversionPattern;
34 
35  LogicalResult
36  matchAndRewrite(Operation *op, ArrayRef<Value> operands,
37  ConversionPatternRewriter &rewriter) const override {
38  return doTypeConversion(op, operands, rewriter, getTypeConverter());
39  }
40 };
41 
42 // Specialization of the above which targets a specific operation.
43 template <typename OpTy>
47 
48  LogicalResult
49  matchAndRewrite(OpTy op, OpAdaptor adaptor,
50  ConversionPatternRewriter &rewriter) const override {
51  return doTypeConversion(op.getOperation(), adaptor.getOperands(), rewriter,
52  this->getTypeConverter());
53  }
54 };
55 
56 } // namespace circt
57 
58 #endif // CIRCT_SUPPORT_CONVERSIONPATTERNS_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
LogicalResult doTypeConversion(Operation *op, ValueRange operands, ConversionPatternRewriter &rewriter, const TypeConverter *typeConverter)
Generic pattern which replaces an operation by one of the same operation name, but with converted att...
TypeConversionPattern(TypeConverter &converter, MLIRContext *context)
LogicalResult matchAndRewrite(Operation *op, ArrayRef< Value > operands, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(OpTy op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
typename mlir::OpConversionPattern< OpTy >::OpAdaptor OpAdaptor