12 #include "mlir/IR/BuiltinAttributes.h"
13 #include "mlir/IR/PatternMatch.h"
15 using namespace circt;
18 LogicalResult WrapValidReadyOp::fold(FoldAdaptor,
19 SmallVectorImpl<OpFoldResult> &results) {
20 if (!getChanOutput().getUsers().
empty())
28 LogicalResult UnwrapFIFOOp::mergeAndErase(UnwrapFIFOOp
unwrap, WrapFIFOOp
wrap,
29 PatternRewriter &rewriter) {
32 rewriter.replaceOp(
wrap, {{},
unwrap.getRden()});
38 PatternRewriter &rewriter) {
39 auto wrap = dyn_cast_or_null<WrapFIFOOp>(op.getChanInput().getDefiningOp());
40 if (succeeded(UnwrapFIFOOp::mergeAndErase(op,
wrap, rewriter)))
45 LogicalResult WrapFIFOOp::fold(FoldAdaptor,
46 SmallVectorImpl<OpFoldResult> &results) {
47 if (getChanOutput().getUsers().
empty()) {
48 results.push_back({});
57 PatternRewriter &rewriter) {
59 dyn_cast_or_null<UnwrapFIFOOp>(*op.getChanOutput().getUsers().begin());
60 if (succeeded(UnwrapFIFOOp::mergeAndErase(
unwrap, op, rewriter)))
65 OpFoldResult WrapWindow::fold(FoldAdaptor) {
66 if (
auto unwrap = dyn_cast_or_null<UnwrapWindow>(getFrame().getDefiningOp()))
70 OpFoldResult UnwrapWindow::fold(FoldAdaptor) {
71 if (
auto wrap = dyn_cast_or_null<WrapWindow>(getWindow().getDefiningOp()))
72 return wrap.getFrame();
77 PatternRewriter &rewriter) {
78 Value bundle = pack.getBundle();
82 if (!bundle.hasOneUse())
83 return rewriter.notifyMatchFailure(pack,
84 "bundle has zero or more than one user");
87 auto unpack = dyn_cast<UnpackBundleOp>(*bundle.getUsers().begin());
90 llvm::zip_equal(pack.getToChannels(), unpack.getToChannels()))
91 rewriter.replaceAllUsesWith(b, a);
93 llvm::zip_equal(unpack.getFromChannels(), pack.getFromChannels()))
94 rewriter.replaceAllUsesWith(b, a);
95 rewriter.eraseOp(unpack);
96 rewriter.eraseOp(pack);
99 return rewriter.notifyMatchFailure(pack,
100 "could not find corresponding unpack");
104 PatternRewriter &rewriter) {
105 Value bundle = unpack.getBundle();
109 if (!bundle.hasOneUse())
110 return rewriter.notifyMatchFailure(unpack,
111 "bundle has zero or more than one user");
114 auto pack = dyn_cast_or_null<PackBundleOp>(bundle.getDefiningOp());
117 return rewriter.notifyMatchFailure(unpack,
118 "could not find corresponding pack");
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
static InstancePath empty
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
static LogicalResult canonicalize(Op op, PatternRewriter &rewriter)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.