xref: /llvm-project/mlir/lib/Dialect/Arith/Transforms/BufferViewFlowOpInterfaceImpl.cpp (revision a45e58af1b381cf3c0374332386b8291ec5310f4)
1 //===- BufferViewFlowOpInterfaceImpl.cpp - Buffer View Flow Analysis ------===//
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/Arith/Transforms/BufferViewFlowOpInterfaceImpl.h"
10 
11 #include "mlir/Dialect/Arith/IR/Arith.h"
12 #include "mlir/Dialect/Bufferization/IR/BufferViewFlowOpInterface.h"
13 
14 using namespace mlir;
15 using namespace mlir::bufferization;
16 
17 namespace mlir {
18 namespace arith {
19 namespace {
20 
21 struct SelectOpInterface
22     : public BufferViewFlowOpInterface::ExternalModel<SelectOpInterface,
23                                                       SelectOp> {
24   void
populateDependenciesmlir::arith::__anon4a0ef3550111::SelectOpInterface25   populateDependencies(Operation *op,
26                        RegisterDependenciesFn registerDependenciesFn) const {
27     auto selectOp = cast<SelectOp>(op);
28 
29     // Either one of the true/false value may be selected at runtime.
30     registerDependenciesFn(selectOp.getTrueValue(), selectOp.getResult());
31     registerDependenciesFn(selectOp.getFalseValue(), selectOp.getResult());
32   }
33 };
34 
35 } // namespace
36 } // namespace arith
37 } // namespace mlir
38 
registerBufferViewFlowOpInterfaceExternalModels(DialectRegistry & registry)39 void arith::registerBufferViewFlowOpInterfaceExternalModels(
40     DialectRegistry &registry) {
41   registry.addExtension(+[](MLIRContext *ctx, arith::ArithDialect *dialect) {
42     SelectOp::attachInterface<SelectOpInterface>(*ctx);
43   });
44 }
45