xref: /llvm-project/mlir/lib/Dialect/Arith/Transforms/BufferViewFlowOpInterfaceImpl.cpp (revision a45e58af1b381cf3c0374332386b8291ec5310f4)
1*a45e58afSMatthias Springer //===- BufferViewFlowOpInterfaceImpl.cpp - Buffer View Flow Analysis ------===//
2*a45e58afSMatthias Springer //
3*a45e58afSMatthias Springer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*a45e58afSMatthias Springer // See https://llvm.org/LICENSE.txt for license information.
5*a45e58afSMatthias Springer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*a45e58afSMatthias Springer //
7*a45e58afSMatthias Springer //===----------------------------------------------------------------------===//
8*a45e58afSMatthias Springer 
9*a45e58afSMatthias Springer #include "mlir/Dialect/Arith/Transforms/BufferViewFlowOpInterfaceImpl.h"
10*a45e58afSMatthias Springer 
11*a45e58afSMatthias Springer #include "mlir/Dialect/Arith/IR/Arith.h"
12*a45e58afSMatthias Springer #include "mlir/Dialect/Bufferization/IR/BufferViewFlowOpInterface.h"
13*a45e58afSMatthias Springer 
14*a45e58afSMatthias Springer using namespace mlir;
15*a45e58afSMatthias Springer using namespace mlir::bufferization;
16*a45e58afSMatthias Springer 
17*a45e58afSMatthias Springer namespace mlir {
18*a45e58afSMatthias Springer namespace arith {
19*a45e58afSMatthias Springer namespace {
20*a45e58afSMatthias Springer 
21*a45e58afSMatthias Springer struct SelectOpInterface
22*a45e58afSMatthias Springer     : public BufferViewFlowOpInterface::ExternalModel<SelectOpInterface,
23*a45e58afSMatthias Springer                                                       SelectOp> {
24*a45e58afSMatthias Springer   void
populateDependenciesmlir::arith::__anon4a0ef3550111::SelectOpInterface25*a45e58afSMatthias Springer   populateDependencies(Operation *op,
26*a45e58afSMatthias Springer                        RegisterDependenciesFn registerDependenciesFn) const {
27*a45e58afSMatthias Springer     auto selectOp = cast<SelectOp>(op);
28*a45e58afSMatthias Springer 
29*a45e58afSMatthias Springer     // Either one of the true/false value may be selected at runtime.
30*a45e58afSMatthias Springer     registerDependenciesFn(selectOp.getTrueValue(), selectOp.getResult());
31*a45e58afSMatthias Springer     registerDependenciesFn(selectOp.getFalseValue(), selectOp.getResult());
32*a45e58afSMatthias Springer   }
33*a45e58afSMatthias Springer };
34*a45e58afSMatthias Springer 
35*a45e58afSMatthias Springer } // namespace
36*a45e58afSMatthias Springer } // namespace arith
37*a45e58afSMatthias Springer } // namespace mlir
38*a45e58afSMatthias Springer 
registerBufferViewFlowOpInterfaceExternalModels(DialectRegistry & registry)39*a45e58afSMatthias Springer void arith::registerBufferViewFlowOpInterfaceExternalModels(
40*a45e58afSMatthias Springer     DialectRegistry &registry) {
41*a45e58afSMatthias Springer   registry.addExtension(+[](MLIRContext *ctx, arith::ArithDialect *dialect) {
42*a45e58afSMatthias Springer     SelectOp::attachInterface<SelectOpInterface>(*ctx);
43*a45e58afSMatthias Springer   });
44*a45e58afSMatthias Springer }
45