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
19 using namespace mlir;
20 using namespace mlir::bufferization;
21
22 namespace mlir {
23 namespace cf {
24 namespace {
25
26 template <typename ConcreteModel, typename ConcreteOp>
27 struct BranchLikeOpInterface
28 : public BranchOpBufferizableOpInterfaceExternalModel<ConcreteModel,
29 ConcreteOp> {
bufferizesToMemoryReadmlir::cf::__anon7040259a0111::BranchLikeOpInterface30 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
31 const AnalysisState &state) const {
32 return false;
33 }
34
bufferizesToMemoryWritemlir::cf::__anon7040259a0111::BranchLikeOpInterface35 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
36 const AnalysisState &state) const {
37 return false;
38 }
39
verifyAnalysismlir::cf::__anon7040259a0111::BranchLikeOpInterface40 LogicalResult verifyAnalysis(Operation *op,
41 const AnalysisState &state) const {
42 return success();
43 }
44
bufferizemlir::cf::__anon7040259a0111::BranchLikeOpInterface45 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.
53 struct BranchOpInterface
54 : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {};
55
56 /// Bufferization of cf.cond_br.
57 struct CondBranchOpInterface
58 : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {};
59
60 } // namespace
61 } // namespace cf
62 } // namespace mlir
63
registerBufferizableOpInterfaceExternalModels(DialectRegistry & registry)64 void mlir::cf::registerBufferizableOpInterfaceExternalModels(
65 DialectRegistry ®istry) {
66 registry.addExtension(+[](MLIRContext *ctx, cf::ControlFlowDialect *dialect) {
67 cf::BranchOp::attachInterface<BranchOpInterface>(*ctx);
68 cf::CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx);
69 });
70 }
71