1//===- BufferizableOpInterfaceImpl.cpp - Impl. of BufferizableOpInterface -===//
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#include "mlir/Dialect/ControlFlow/Transforms/BufferizableOpInterfaceImpl.h"
10
11#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
12#include "mlir/Dialect/Bufferization/IR/UnstructuredControlFlow.h"
13#include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h"
14#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
15#include "mlir/Dialect/MemRef/IR/MemRef.h"
16#include "mlir/IR/Dialect.h"
17#include "mlir/IR/Operation.h"
18
19using namespace mlir;
20using namespace mlir::bufferization;
21
22namespace mlir {
23namespace cf {
24namespace {
25
26template <typename ConcreteModel, typename ConcreteOp>
27struct BranchLikeOpInterface
28 : public BranchOpBufferizableOpInterfaceExternalModel<ConcreteModel,
29 ConcreteOp> {
30 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
31 const AnalysisState &state) const {
32 return false;
33 }
34
35 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
36 const AnalysisState &state) const {
37 return false;
38 }
39
40 LogicalResult verifyAnalysis(Operation *op,
41 const AnalysisState &state) const {
42 return success();
43 }
44
45 LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
46 const BufferizationOptions &options) const {
47 // The operands of this op are bufferized together with the block signature.
48 return success();
49 }
50};
51
52/// Bufferization of cf.br.
53struct BranchOpInterface
54 : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {};
55
56/// Bufferization of cf.cond_br.
57struct CondBranchOpInterface
58 : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {};
59
60} // namespace
61} // namespace cf
62} // namespace mlir
63
64void mlir::cf::registerBufferizableOpInterfaceExternalModels(
65 DialectRegistry &registry) {
66 registry.addExtension(extensionFn: +[](MLIRContext *ctx, cf::ControlFlowDialect *dialect) {
67 cf::BranchOp::attachInterface<BranchOpInterface>(*ctx);
68 cf::CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx);
69 });
70}
71

source code of mlir/lib/Dialect/ControlFlow/Transforms/BufferizableOpInterfaceImpl.cpp