MLIR 22.0.0git
BubbleDownMemorySpaceCasts.cpp
Go to the documentation of this file.
1//===- BubbleDownMemorySpaceCasts.cpp - Bubble down casts transform -------===//
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
12#include "mlir/Pass/Pass.h"
15#include "llvm/Support/Debug.h"
16
17using namespace mlir;
18
19namespace mlir {
20#define GEN_PASS_DEF_BUBBLEDOWNMEMORYSPACECASTS
21#include "mlir/Transforms/Passes.h.inc"
22} // namespace mlir
23
24namespace {
25//===----------------------------------------------------------------------===//
26// BubbleDownCastsPattern pattern
27//===----------------------------------------------------------------------===//
28/// Pattern to bubble down casts into consumer operations.
29struct BubbleDownCastsPattern
30 : public OpInterfaceRewritePattern<MemorySpaceCastConsumerOpInterface> {
32
33 LogicalResult matchAndRewrite(MemorySpaceCastConsumerOpInterface op,
34 PatternRewriter &rewriter) const override {
35 FailureOr<std::optional<SmallVector<Value>>> results =
36 op.bubbleDownCasts(rewriter);
37 if (failed(results))
38 return failure();
39 if (!results->has_value()) {
40 rewriter.modifyOpInPlace(op, []() {});
41 return success();
42 }
43 rewriter.replaceOp(op, **results);
44 return success();
45 }
46};
48//===----------------------------------------------------------------------===//
49// BubbleDownMemorySpaceCasts pass
50//===----------------------------------------------------------------------===//
52struct BubbleDownMemorySpaceCasts
53 : public impl::BubbleDownMemorySpaceCastsBase<BubbleDownMemorySpaceCasts> {
55 BubbleDownMemorySpaceCasts>::BubbleDownMemorySpaceCastsBase;
56
60 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
62 }
63};
64} // namespace
68 patterns.add<BubbleDownCastsPattern>(patterns.getContext(), benefit);
69}
return success()
b getContext())
OpT getOperation()
Return the current operation being transformed.
Definition Pass.h:378
virtual void runOnOperation()=0
The polymorphic API that runs the pass over the currently held operation.
void signalPassFailure()
Signal that some invariant was broken when running.
Definition Pass.h:218
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:561
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region &region, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
void populateBubbleDownMemorySpaceCastPatterns(RewritePatternSet &patterns, PatternBenefit benefit)
Collect a set of patterns to bubble-down memory-space cast operations.
OpInterfaceRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting a...
OpInterfaceRewritePattern(MLIRContext *context, PatternBenefit benefit=1)