CIRCT
22.0.0git
Loading...
Searching...
No Matches
include
circt
Support
ConversionPatternSet.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
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
// Utilities to collect sets of conversion patterns.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef CIRCT_SUPPORT_CONVERSIONPATTERNSET_H
14
#define CIRCT_SUPPORT_CONVERSIONPATTERNSET_H
15
16
#include "
circt/Support/LLVM.h
"
17
#include "mlir/IR/PatternMatch.h"
18
19
namespace
circt
{
20
21
/// Extension of `RewritePatternSet` that allows adding `matchAndRewrite`
22
/// functions with op adaptors and `ConversionPatternRewriter` as patterns.
23
class
ConversionPatternSet
:
public
RewritePatternSet {
24
public
:
25
const
TypeConverter &
typeConverter
;
26
27
ConversionPatternSet
(MLIRContext *
context
,
const
TypeConverter &
typeConverter
)
28
: RewritePatternSet(
context
),
typeConverter
(
typeConverter
) {}
29
30
// Expose the `add` implementations of `RewritePatternSet`.
31
using
RewritePatternSet::add;
32
33
/// Add a `matchAndRewrite` function as a conversion pattern to the set.
34
template
<
class
Op>
35
ConversionPatternSet
&
36
add
(LogicalResult (*implFn)(Op,
typename
Op::Adaptor,
37
ConversionPatternRewriter &)) {
38
39
struct
FnPattern final :
public
OpConversionPattern
<Op> {
40
using
OpConversionPattern
<Op>::OpConversionPattern;
41
LogicalResult (*implFn)(Op,
typename
Op::Adaptor,
42
ConversionPatternRewriter &);
43
44
LogicalResult
45
matchAndRewrite(Op op,
typename
Op::Adaptor adaptor,
46
ConversionPatternRewriter &rewriter)
const override
{
47
return
implFn(op, adaptor, rewriter);
48
}
49
};
50
51
auto
pattern
= std::make_unique<FnPattern>(
typeConverter
, getContext());
52
pattern
->implFn = implFn;
53
add
(std::move(
pattern
));
54
return
*
this
;
55
}
56
57
/// Add a `matchAndRewrite` function as a conversion pattern to the set.
58
template
<
class
Op>
59
ConversionPatternSet
&
add
(LogicalResult (*implFn)(Op,
typename
Op::Adaptor,
60
ConversionPatternRewriter &,
61
const
TypeConverter &)) {
62
63
struct
FnPattern final :
public
OpConversionPattern
<Op> {
64
using
OpConversionPattern
<Op>::OpConversionPattern;
65
LogicalResult (*implFn)(Op,
typename
Op::Adaptor,
66
ConversionPatternRewriter &,
67
const
TypeConverter &);
68
69
LogicalResult
70
matchAndRewrite(Op op,
typename
Op::Adaptor adaptor,
71
ConversionPatternRewriter &rewriter)
const override
{
72
return
implFn(op, adaptor, rewriter, *this->typeConverter);
73
}
74
};
75
76
auto
pattern
= std::make_unique<FnPattern>(
typeConverter
, getContext());
77
pattern
->implFn = implFn;
78
add
(std::move(
pattern
));
79
return
*
this
;
80
}
81
};
82
83
}
// namespace circt
84
85
#endif
// CIRCT_SUPPORT_CONVERSIONPATTERNSET_H
context
static std::unique_ptr< Context > context
Definition
DpiEntryPoints.cpp:37
LLVM.h
pattern
RewritePatternSet pattern
Definition
SCFToCalyx.cpp:2686
circt::ConversionPatternSet
Extension of RewritePatternSet that allows adding matchAndRewrite functions with op adaptors and Conv...
Definition
ConversionPatternSet.h:23
circt::ConversionPatternSet::ConversionPatternSet
ConversionPatternSet(MLIRContext *context, const TypeConverter &typeConverter)
Definition
ConversionPatternSet.h:27
circt::ConversionPatternSet::add
ConversionPatternSet & add(LogicalResult(*implFn)(Op, typename Op::Adaptor, ConversionPatternRewriter &, const TypeConverter &))
Add a matchAndRewrite function as a conversion pattern to the set.
Definition
ConversionPatternSet.h:59
circt::ConversionPatternSet::add
ConversionPatternSet & add(LogicalResult(*implFn)(Op, typename Op::Adaptor, ConversionPatternRewriter &))
Add a matchAndRewrite function as a conversion pattern to the set.
Definition
ConversionPatternSet.h:36
circt::ConversionPatternSet::typeConverter
const TypeConverter & typeConverter
Definition
ConversionPatternSet.h:25
mlir::OpConversionPattern
Definition
LLVM.h:176
circt
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition
DebugAnalysis.h:21
Generated on Wed Dec 17 2025 00:08:53 for CIRCT by
1.9.8