diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h b/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h @@ -25,12 +25,6 @@ raw_ostream &operator<<(raw_ostream &os, Range &range); -/// Return the list of Range (i.e. offset, size, stride). Each Range -/// entry contains either the dynamic value or a ConstantIndexOp constructed -/// with `b` at location `loc`. -SmallVector getOrCreateRanges(OffsetSizeAndStrideOpInterface op, - OpBuilder &b, Location loc); - /// Given an operation, retrieves the value of each dynamic dimension through /// constructing the necessary DimOp operators. SmallVector getDynOperands(Location loc, Value val, OpBuilder &b); diff --git a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h --- a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h +++ b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h @@ -18,20 +18,6 @@ #include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/ViewLikeInterface.h" -//===----------------------------------------------------------------------===// -// Tensor Dialect Helpers -//===----------------------------------------------------------------------===// - -namespace mlir { - -/// Return the list of Range (i.e. offset, size, stride). Each Range -/// entry contains either the dynamic value or a ConstantIndexOp constructed -/// with `b` at location `loc`. -SmallVector getOrCreateRanges(OffsetSizeAndStrideOpInterface op, - OpBuilder &b, Location loc); - -} // namespace mlir - //===----------------------------------------------------------------------===// // Tensor Dialect //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2234,7 +2234,7 @@ /// Range entry contains either the dynamic value or a ConstantIndexOp /// constructed with `b` at location `loc`. SmallVector getOrCreateRanges(OpBuilder &b, Location loc) { - return mlir::getOrCreateRanges(*this, b, loc); + return mlir::detail::getOrCreateRanges(*this, b, loc); } }]; } diff --git a/mlir/include/mlir/Interfaces/ViewLikeInterface.h b/mlir/include/mlir/Interfaces/ViewLikeInterface.h --- a/mlir/include/mlir/Interfaces/ViewLikeInterface.h +++ b/mlir/include/mlir/Interfaces/ViewLikeInterface.h @@ -33,6 +33,9 @@ bool isEqualConstantInt(OpFoldResult ofr, int64_t value); namespace detail { +SmallVector getOrCreateRanges(OffsetSizeAndStrideOpInterface op, + OpBuilder &b, Location loc); + LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op); bool sameOffsetsSizesAndStrides( diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -1827,34 +1827,6 @@ << range.stride; } -/// Return the list of Range (i.e. offset, size, stride). Each Range -/// entry contains either the dynamic value or a ConstantIndexOp constructed -/// with `b` at location `loc`. -SmallVector mlir::getOrCreateRanges(OffsetSizeAndStrideOpInterface op, - OpBuilder &b, Location loc) { - std::array ranks = op.getArrayAttrMaxRanks(); - assert(ranks[0] == ranks[1] && "expected offset and sizes of equal ranks"); - assert(ranks[1] == ranks[2] && "expected sizes and strides of equal ranks"); - SmallVector res; - unsigned rank = ranks[0]; - res.reserve(rank); - for (unsigned idx = 0; idx < rank; ++idx) { - Value offset = - op.isDynamicOffset(idx) - ? op.getDynamicOffset(idx) - : b.create(loc, op.getStaticOffset(idx)); - Value size = op.isDynamicSize(idx) - ? op.getDynamicSize(idx) - : b.create(loc, op.getStaticSize(idx)); - Value stride = - op.isDynamicStride(idx) - ? op.getDynamicStride(idx) - : b.create(loc, op.getStaticStride(idx)); - res.emplace_back(Range{offset, size, stride}); - } - return res; -} - /// Infer the canonical type of the result of a subview operation. Returns a /// type with rank `resultRank` that is either the rank of the rank-reduced /// type, or the non-rank-reduced type. diff --git a/mlir/lib/Interfaces/CMakeLists.txt b/mlir/lib/Interfaces/CMakeLists.txt --- a/mlir/lib/Interfaces/CMakeLists.txt +++ b/mlir/lib/Interfaces/CMakeLists.txt @@ -27,7 +27,6 @@ ) endfunction(add_mlir_interface_library) - add_mlir_interface_library(CallInterfaces) add_mlir_interface_library(CastInterfaces) add_mlir_interface_library(ControlFlowInterfaces) @@ -38,5 +37,17 @@ add_mlir_interface_library(LoopLikeInterface) add_mlir_interface_library(SideEffectInterfaces) add_mlir_interface_library(VectorInterfaces) -add_mlir_interface_library(ViewLikeInterface) +add_mlir_library(MLIRViewLikeInterface + ViewLikeInterface.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces + + DEPENDS + MLIRViewLikeInterfaceIncGen + + LINK_LIBS PUBLIC + MLIRIR + MLIRStandardOps + ) diff --git a/mlir/lib/Interfaces/ViewLikeInterface.cpp b/mlir/lib/Interfaces/ViewLikeInterface.cpp --- a/mlir/lib/Interfaces/ViewLikeInterface.cpp +++ b/mlir/lib/Interfaces/ViewLikeInterface.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Interfaces/ViewLikeInterface.h" +#include "mlir/Dialect/StandardOps/IR/Ops.h" using namespace mlir; @@ -17,6 +18,35 @@ /// Include the definitions of the loop-like interfaces. #include "mlir/Interfaces/ViewLikeInterface.cpp.inc" +/// Return the list of Range (i.e. offset, size, stride). Each Range +/// entry contains either the dynamic value or a ConstantIndexOp constructed +/// with `b` at location `loc`. +SmallVector +mlir::detail::getOrCreateRanges(OffsetSizeAndStrideOpInterface op, OpBuilder &b, + Location loc) { + std::array ranks = op.getArrayAttrMaxRanks(); + assert(ranks[0] == ranks[1] && "expected offset and sizes of equal ranks"); + assert(ranks[1] == ranks[2] && "expected sizes and strides of equal ranks"); + SmallVector res; + unsigned rank = ranks[0]; + res.reserve(rank); + for (unsigned idx = 0; idx < rank; ++idx) { + Value offset = + op.isDynamicOffset(idx) + ? op.getDynamicOffset(idx) + : b.create(loc, op.getStaticOffset(idx)); + Value size = op.isDynamicSize(idx) + ? op.getDynamicSize(idx) + : b.create(loc, op.getStaticSize(idx)); + Value stride = + op.isDynamicStride(idx) + ? op.getDynamicStride(idx) + : b.create(loc, op.getStaticStride(idx)); + res.emplace_back(Range{offset, size, stride}); + } + return res; +} + LogicalResult mlir::verifyListOfOperandsOrIntegers( Operation *op, StringRef name, unsigned maxNumElements, ArrayAttr attr, ValueRange values, llvm::function_ref isDynamic) {