xref: /llvm-project/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp (revision 485cc55edfb875628e19bb6d9de4706af2865d3e)
1 //===----------------------------------------------------------------------===//
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/MemRef/IR/MemRef.h"
10 #include "mlir/Transforms/InliningUtils.h"
11 
12 using namespace mlir;
13 using namespace mlir::memref;
14 
15 #include "mlir/Dialect/MemRef/IR/MemRefOpsDialect.cpp.inc"
16 
17 //===----------------------------------------------------------------------===//
18 // MemRefDialect Dialect Interfaces
19 //===----------------------------------------------------------------------===//
20 
21 namespace {
22 struct MemRefInlinerInterface : public DialectInlinerInterface {
23   using DialectInlinerInterface::DialectInlinerInterface;
24   bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
25                        BlockAndValueMapping &valueMapping) const final {
26     return true;
27   }
28   bool isLegalToInline(Operation *, Region *, bool wouldBeCloned,
29                        BlockAndValueMapping &) const final {
30     return true;
31   }
32 };
33 } // end anonymous namespace
34 
35 SmallVector<Value, 4> mlir::getDynOperands(Location loc, Value val,
36                                            OpBuilder &b) {
37   SmallVector<Value, 4> dynOperands;
38   auto shapedType = val.getType().cast<ShapedType>();
39   for (auto dim : llvm::enumerate(shapedType.getShape())) {
40     if (dim.value() == MemRefType::kDynamicSize)
41       dynOperands.push_back(b.create<memref::DimOp>(loc, val, dim.index()));
42   }
43   return dynOperands;
44 }
45 
46 void mlir::memref::MemRefDialect::initialize() {
47   addOperations<DmaStartOp, DmaWaitOp,
48 #define GET_OP_LIST
49 #include "mlir/Dialect/MemRef/IR/MemRefOps.cpp.inc"
50                 >();
51   addInterfaces<MemRefInlinerInterface>();
52 }
53