| 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> { |
| 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, |
| 47 | BufferizationState &state) const { |
| 48 | // The operands of this op are bufferized together with the block signature. |
| 49 | return success(); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | /// Bufferization of cf.br. |
| 54 | struct BranchOpInterface |
| 55 | : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {}; |
| 56 | |
| 57 | /// Bufferization of cf.cond_br. |
| 58 | struct CondBranchOpInterface |
| 59 | : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {}; |
| 60 | |
| 61 | } // namespace |
| 62 | } // namespace cf |
| 63 | } // namespace mlir |
| 64 | |
| 65 | void mlir::cf::registerBufferizableOpInterfaceExternalModels( |
| 66 | DialectRegistry ®istry) { |
| 67 | registry.addExtension(extensionFn: +[](MLIRContext *ctx, cf::ControlFlowDialect *dialect) { |
| 68 | cf::BranchOp::attachInterface<BranchOpInterface>(*ctx); |
| 69 | cf::CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx); |
| 70 | }); |
| 71 | } |
| 72 | |