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