1 //===- BufferizableOpInterface.cpp - Bufferizable Ops  ---=----------------===//
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/Bufferization/IR/BufferizableOpInterface.h"
10 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
11 #include "mlir/Dialect/MemRef/IR/MemRef.h"
12 #include "mlir/IR/AsmState.h"
13 #include "mlir/IR/BlockAndValueMapping.h"
14 #include "mlir/IR/BuiltinOps.h"
15 #include "mlir/IR/Operation.h"
16 #include "mlir/IR/TypeUtilities.h"
17 #include "mlir/IR/Value.h"
18 #include "llvm/Support/Debug.h"
19 
20 namespace mlir {
21 namespace bufferization {
22 
23 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.cpp.inc"
24 
25 } // namespace bufferization
26 } // namespace mlir
27 
28 #define DEBUG_TYPE "bufferizable-op-interface"
29 #define DBGS() (llvm::dbgs() << '[' << DEBUG_TYPE << "] ")
30 #define LDBG(X) LLVM_DEBUG(DBGS() << (X))
31 
32 using namespace mlir;
33 using namespace bufferization;
34 
35 /// Attribute name used to mark the bufferization layout for region
36 /// arguments during linalg comprehensive bufferization.
37 constexpr const ::llvm::StringLiteral
38     bufferization::BufferizableOpInterface::kBufferLayoutAttrName;
39 
40 /// Attribute name used to mark region arguments that can be bufferized
41 /// in-place during linalg comprehensive bufferization.
42 constexpr const ::llvm::StringLiteral
43     bufferization::BufferizableOpInterface::kInplaceableAttrName;
44 
45 //===----------------------------------------------------------------------===//
46 // BufferizationOptions
47 //===----------------------------------------------------------------------===//
48 
49 // Default constructor for BufferizationOptions.
50 BufferizationOptions::BufferizationOptions() = default;
51 
52 BufferizableOpInterface
53 BufferizationOptions::dynCastBufferizableOp(Operation *op) const {
54   if (isOpAllowed(op))
55     return dyn_cast<BufferizableOpInterface>(op);
56   return nullptr;
57 }
58 
59 BufferizableOpInterface
60 BufferizationOptions::dynCastBufferizableOp(Value value) const {
61   if (auto bufferizableOp = value.getDefiningOp<BufferizableOpInterface>())
62     if (isOpAllowed(bufferizableOp.getOperation()))
63       return bufferizableOp;
64   return nullptr;
65 }
66 
67 //===----------------------------------------------------------------------===//
68 // Helper functions for BufferizableOpInterface
69 //===----------------------------------------------------------------------===//
70 
71 static void setInsertionPointAfter(OpBuilder &b, Value value) {
72   if (auto bbArg = value.dyn_cast<BlockArgument>()) {
73     b.setInsertionPointToStart(bbArg.getOwner());
74   } else {
75     b.setInsertionPointAfter(value.getDefiningOp());
76   }
77 }
78 
79 /// Determine which OpOperand* will alias with `result` if the op is bufferized
80 /// in place. Return an empty vector if the op is not bufferizable.
81 SmallVector<OpOperand *>
82 BufferizationState::getAliasingOpOperand(OpResult result) const {
83   if (Operation *op = result.getDefiningOp())
84     if (auto bufferizableOp = dyn_cast<BufferizableOpInterface>(op))
85       return bufferizableOp.getAliasingOpOperand(result, *this);
86   return {};
87 }
88 
89 /// Determine which OpResult will alias with `opOperand` if the op is bufferized
90 /// in place. Return an empty vector if the op is not bufferizable.
91 SmallVector<OpResult>
92 BufferizationState::getAliasingOpResult(OpOperand &opOperand) const {
93   if (auto bufferizableOp =
94           dyn_cast<BufferizableOpInterface>(opOperand.getOwner()))
95     return bufferizableOp.getAliasingOpResult(opOperand, *this);
96   return {};
97 }
98 
99 /// Return true if `opOperand` bufferizes to a memory read. Return `true` if the
100 /// op is not bufferizable.
101 bool BufferizationState::bufferizesToMemoryRead(OpOperand &opOperand) const {
102   if (auto bufferizableOp =
103           dyn_cast<BufferizableOpInterface>(opOperand.getOwner()))
104     return bufferizableOp.bufferizesToMemoryRead(opOperand, *this);
105 
106   // Unknown op that returns a tensor. The inplace analysis does not support it.
107   // Conservatively return true.
108   return true;
109 }
110 
111 /// Return true if `opOperand` bufferizes to a memory write. Return
112 /// `true` if the op is not bufferizable.
113 bool BufferizationState::bufferizesToMemoryWrite(OpOperand &opOperand) const {
114   if (auto bufferizableOp =
115           dyn_cast<BufferizableOpInterface>(opOperand.getOwner()))
116     return bufferizableOp.bufferizesToMemoryWrite(opOperand, *this);
117 
118   // Unknown op that returns a tensor. The inplace analysis does not support it.
119   // Conservatively return true.
120   return true;
121 }
122 
123 /// Return true if `opOperand` does neither read nor write but bufferizes to an
124 /// alias. Return false if the op is not bufferizable.
125 bool BufferizationState::bufferizesToAliasOnly(OpOperand &opOperand) const {
126   if (auto bufferizableOp =
127           dyn_cast<BufferizableOpInterface>(opOperand.getOwner()))
128     return bufferizableOp.bufferizesToAliasOnly(opOperand, *this);
129 
130   // Unknown op that returns a tensor. The inplace analysis does not support it.
131   // Conservatively return false.
132   return false;
133 }
134 
135 /// Return true if the given value is read by an op that bufferizes to a memory
136 /// read. Also takes into account ops that create an alias but do not read by
137 /// themselves (e.g., ExtractSliceOp).
138 bool BufferizationState::isValueRead(Value value) const {
139   assert(value.getType().isa<TensorType>() && "expected TensorType");
140   SmallVector<OpOperand *> workingSet;
141   for (OpOperand &use : value.getUses())
142     workingSet.push_back(&use);
143 
144   while (!workingSet.empty()) {
145     OpOperand *uMaybeReading = workingSet.pop_back_val();
146     // Skip over all ops that neither read nor write (but create an alias).
147     if (bufferizesToAliasOnly(*uMaybeReading))
148       for (OpResult opResult : getAliasingOpResult(*uMaybeReading))
149         for (OpOperand &use : opResult.getUses())
150           workingSet.push_back(&use);
151     if (bufferizesToMemoryRead(*uMaybeReading))
152       return true;
153   }
154 
155   return false;
156 }
157 
158 // Starting from `value`, follow the use-def chain in reverse, always selecting
159 // the aliasing OpOperands. Find and return Values for which `condition`
160 // evaluates to true. OpOperands of such matching Values are not traversed any
161 // further.
162 llvm::SetVector<Value> BufferizationState::findValueInReverseUseDefChain(
163     Value value, llvm::function_ref<bool(Value)> condition) const {
164   llvm::SetVector<Value> result, workingSet;
165   workingSet.insert(value);
166 
167   while (!workingSet.empty()) {
168     Value value = workingSet.pop_back_val();
169     if (condition(value) || value.isa<BlockArgument>()) {
170       result.insert(value);
171       continue;
172     }
173 
174     OpResult opResult = value.cast<OpResult>();
175     SmallVector<OpOperand *> opOperands = getAliasingOpOperand(opResult);
176     if (opOperands.empty() || !options.isOpAllowed(value.getDefiningOp())) {
177       result.insert(value);
178       continue;
179     }
180 
181     for (OpOperand *o : opOperands)
182       workingSet.insert(o->get());
183   }
184 
185   return result;
186 }
187 
188 // Find the Values of the last preceding write of a given Value.
189 llvm::SetVector<Value>
190 BufferizationState::findLastPrecedingWrite(Value value) const {
191   return findValueInReverseUseDefChain(value, [&](Value value) {
192     Operation *op = value.getDefiningOp();
193     if (!op)
194       return true;
195     auto bufferizableOp = options.dynCastBufferizableOp(op);
196     if (!bufferizableOp)
197       return true;
198     return bufferizableOp.isMemoryWrite(value.cast<OpResult>(), *this);
199   });
200 }
201 
202 BufferizationState::BufferizationState(const BufferizationOptions &options)
203     : options(options) {}
204 
205 // bufferization.to_memref is not allowed to change the rank.
206 static void ensureToMemrefOpIsValid(Value tensor, Type memrefType) {
207 #ifndef NDEBUG
208   auto rankedTensorType = tensor.getType().dyn_cast<RankedTensorType>();
209   assert((!rankedTensorType || memrefType.cast<MemRefType>().getRank() ==
210                                    rankedTensorType.getRank()) &&
211          "to_memref would be invalid: mismatching ranks");
212 #endif
213 }
214 
215 static Value lookupBuffer(RewriterBase &rewriter, Value tensor,
216                           const BufferizationOptions &options) {
217   auto tensorType = tensor.getType().dyn_cast<TensorType>();
218   assert(tensorType && "unexpected non-tensor type");
219 
220   // Replace "%t = to_tensor %m" with %m.
221   if (auto toTensorOp = tensor.getDefiningOp<bufferization::ToTensorOp>())
222     return toTensorOp.memref();
223 
224   // Insert to_memref op.
225   OpBuilder::InsertionGuard g(rewriter);
226   setInsertionPointAfter(rewriter, tensor);
227   Type memrefType = getMemRefType(tensorType, options);
228   ensureToMemrefOpIsValid(tensor, memrefType);
229   return rewriter.create<bufferization::ToMemrefOp>(tensor.getLoc(), memrefType,
230                                                     tensor);
231 }
232 
233 /// Return the result buffer (memref) for a given OpResult (tensor). Allocate
234 /// a new buffer and copy over data from the existing buffer if out-of-place
235 /// bufferization is necessary.
236 FailureOr<Value> BufferizationState::getBuffer(
237     RewriterBase &rewriter, OpOperand &opOperand, bool forceInPlace,
238     Optional<Operation *> customCopyInsertionPoint) const {
239   OpBuilder::InsertionGuard guard(rewriter);
240   Operation *op = opOperand.getOwner();
241   Location loc = op->getLoc();
242   Value operand = opOperand.get();
243   Value operandBuffer = lookupBuffer(rewriter, operand, options);
244 
245   if (forceInPlace || isInPlace(opOperand))
246     return operandBuffer;
247 
248   // Bufferizing out-of-place: Allocate a new buffer.
249   // Move insertion point right after `operandBuffer`. That is where the
250   // allocation should be inserted (in the absence of allocation hoisting).
251   setInsertionPointAfter(rewriter, operandBuffer);
252   // Allocate the result buffer.
253   FailureOr<Value> resultBuffer = createAlloc(rewriter, loc, operandBuffer,
254                                               options.createDeallocs, options);
255   if (failed(resultBuffer))
256     return failure();
257   // Do not copy if the last preceding writes of `operand` are ops that do
258   // not write (skipping ops that merely create aliases). E.g., InitTensorOp.
259   // Note: If `findLastPrecedingWrite` reaches the end of the reverse SSA
260   // use-def chain, it returns that value, regardless of whether it is a
261   // memory write or not.
262   SetVector<Value> lastWrites = findLastPrecedingWrite(operand);
263   if (llvm::none_of(lastWrites, [&](Value lastWrite) {
264         if (auto bufferizableOp = options.dynCastBufferizableOp(lastWrite))
265           return bufferizableOp.isMemoryWrite(lastWrite.cast<OpResult>(),
266                                               *this);
267         return true;
268       }))
269     return resultBuffer;
270   // Do not copy if the copied data is never read.
271   SmallVector<OpResult> aliasingOpResults = getAliasingOpResult(opOperand);
272   if (!aliasingOpResults.empty() && !bufferizesToMemoryRead(opOperand) &&
273       llvm::none_of(aliasingOpResults,
274                     [&](OpResult opResult) { return isValueRead(opResult); }))
275     return resultBuffer;
276   // Do not copy if this op does not read the data, but writes it.
277   if (bufferizesToMemoryWrite(opOperand) && !bufferizesToMemoryRead(opOperand))
278     return resultBuffer;
279 
280   if (customCopyInsertionPoint) {
281     rewriter.setInsertionPoint(*customCopyInsertionPoint);
282   } else {
283     // The copy happens right before the op that is bufferized.
284     rewriter.setInsertionPoint(op);
285   }
286   if (failed(
287           createMemCpy(rewriter, loc, operandBuffer, *resultBuffer, options)))
288     return failure();
289 
290   return resultBuffer;
291 }
292 
293 void bufferization::replaceOpWithBufferizedValues(RewriterBase &rewriter,
294                                                   Operation *op,
295                                                   ValueRange values) {
296   OpBuilder::InsertionGuard g(rewriter);
297 
298   // Replace all OpResults with the given values.
299   for (OpResult opResult : op->getOpResults()) {
300     // Skip OpResult if it has no uses.
301     if (opResult.getUses().empty())
302       continue;
303 
304     Value replacement = values[opResult.getResultNumber()];
305     if (opResult.getType().isa<TensorType>()) {
306       // The OpResult is a tensor. Such values are replaced with memrefs during
307       // bufferization.
308       assert((replacement.getType().isa<MemRefType>() ||
309               replacement.getType().isa<UnrankedMemRefType>()) &&
310              "tensor op result should be replaced with a memref value");
311       // The existing uses of the OpResult still expect a tensor. Insert a
312       // ToTensorOp. Throughout bufferization, this ToTensorOp will gradually
313       // loose all of its users and eventually DCE away.
314       rewriter.setInsertionPointAfter(op);
315       replacement = rewriter.create<bufferization::ToTensorOp>(
316           replacement.getLoc(), replacement);
317     }
318     opResult.replaceAllUsesWith(replacement);
319   }
320 
321   rewriter.eraseOp(op);
322 }
323 
324 AlwaysCopyBufferizationState::AlwaysCopyBufferizationState(
325     const BufferizationOptions &options)
326     : BufferizationState(options) {}
327 
328 /// Return `true` if the given OpResult has been decided to bufferize inplace.
329 bool AlwaysCopyBufferizationState::isInPlace(OpOperand &opOperand) const {
330   // OpOperands that bufferize to a memory write are out-of-place, i.e., an
331   // alloc and copy is inserted.
332   return !bufferizesToMemoryWrite(opOperand);
333 }
334 
335 /// Return true if `v1` and `v2` bufferize to equivalent buffers.
336 bool AlwaysCopyBufferizationState::areEquivalentBufferizedValues(
337     Value v1, Value v2) const {
338   // There is no analysis, so we do not know if the values are equivalent. The
339   // conservative answer is "false".
340   return false;
341 }
342 
343 //===----------------------------------------------------------------------===//
344 // Bufferization-specific scoped alloc/dealloc insertion support.
345 //===----------------------------------------------------------------------===//
346 
347 /// Move the insertion point of the given builder to the beginning of a
348 /// surrounding block as much as possible, while not crossing any allocation
349 /// hoisting barriers.
350 static void moveInsertionPointToAllocationHoistingBarrier(OpBuilder &b) {
351   Operation *op = b.getInsertionBlock()->getParentOp();
352   while (op) {
353     if (auto bufferizableOp = dyn_cast<BufferizableOpInterface>(op))
354       if (bufferizableOp.isAllocationHoistingBarrier())
355         break;
356     op = op->getParentOp();
357   }
358 
359   if (!op) {
360     // No allocation hoisting barrier found. Hoist to FuncOp.
361     op = b.getInsertionBlock()->getParentOp();
362     if (!isa<FuncOp>(op))
363       op = op->getParentOfType<FuncOp>();
364     assert(op && "could not find enclosing FuncOp");
365   }
366 
367   // TODO: Handle cases where allocation hoisting barrier has more than one
368   // region or block.
369   assert(op->getNumRegions() == 1 &&
370          "allocation hoisting barriers with >1 regions not supported");
371   assert(op->getRegion(0).getBlocks().size() == 1 &&
372          "allocation hoisting barriers with >1 blocks not supported");
373   b.setInsertionPointToStart(&(op->getRegion(0).front()));
374 }
375 
376 /// Compute the type of the `memref` to use for allocating the buffer for
377 /// `shapedValue`. Also returns (by reference in `dynShape`), the value for the
378 /// dynamic dimensions in the returned `memref` type. The function may also set
379 /// the insertion point to an earlier location, where the allocation should
380 /// happen ("allocation hoisting").
381 static MemRefType getAllocationTypeAndShape(OpBuilder &b, Location loc,
382                                             Value shapedValue,
383                                             SmallVectorImpl<Value> &dynShape) {
384   MemRefType allocMemRefType =
385       getContiguousMemRefType(shapedValue.getType().cast<ShapedType>());
386 
387   // Compute the dynamic part of the shape.
388   bool reifiedShapes = false;
389   if (auto rankedOp = dyn_cast_or_null<ReifyRankedShapedTypeOpInterface>(
390           shapedValue.getDefiningOp())) {
391     ReifiedRankedShapedTypeDims resultDims;
392     if (succeeded(rankedOp.reifyResultShapes(b, resultDims))) {
393       reifiedShapes = true;
394       OpResult resultValue = shapedValue.dyn_cast<OpResult>();
395       auto &shape = resultDims[resultValue.getResultNumber()];
396       for (const auto &dim : enumerate(allocMemRefType.getShape()))
397         if (ShapedType::isDynamic(dim.value()))
398           dynShape.push_back(shape[dim.index()]);
399     }
400   }
401 
402   if (!reifiedShapes) {
403     for (const auto &dim : enumerate(allocMemRefType.getShape()))
404       if (ShapedType::isDynamic(dim.value())) {
405         assert((shapedValue.getType().isa<UnrankedMemRefType>() ||
406                 shapedValue.getType().isa<MemRefType>()) &&
407                "expected MemRef type");
408         dynShape.push_back(
409             b.create<memref::DimOp>(loc, shapedValue, dim.index()));
410       }
411   }
412 
413   // If the buffer is statically shaped, try to hoist it to the first enclosing
414   // parallel region.
415   // TODO: also hoist in the dynamic case. For now this relies on subsequent
416   // calls to LICM and buffer hoisting which will most likely not succeed.
417   // TODO: when packing, allocate a static bounding box which will enable more
418   // hoisting.
419   if (dynShape.empty())
420     moveInsertionPointToAllocationHoistingBarrier(b);
421 
422   return allocMemRefType;
423 }
424 
425 /// Create an AllocOp/DeallocOp pair, where the AllocOp is after
426 /// `shapedValue.getDefiningOp` (or at the top of the block in case of a
427 /// bbArg) and the DeallocOp is at the end of the block.
428 FailureOr<Value>
429 bufferization::createAlloc(OpBuilder &b, Location loc, Value shapedValue,
430                            bool deallocMemref,
431                            const BufferizationOptions &options) {
432   // Take a guard before anything else.
433   OpBuilder::InsertionGuard g(b);
434 
435   // 1. Create memory allocation.
436   assert(shapedValue.getType().isa<ShapedType>());
437   MemRefType memRefType = shapedValue.getType().dyn_cast<MemRefType>();
438   SmallVector<Value> dynShape;
439   // Note: getAllocationTypeAndShape also sets the insertion point.
440   MemRefType allocMemRefType =
441       getAllocationTypeAndShape(b, loc, shapedValue, dynShape);
442   FailureOr<Value> allocated =
443       createAlloc(b, loc, allocMemRefType, dynShape, options);
444   if (failed(allocated))
445     return failure();
446   Value casted = allocated.getValue();
447   if (memRefType && memRefType != allocMemRefType) {
448     assert(memref::CastOp::areCastCompatible(allocated.getValue().getType(),
449                                              memRefType) &&
450            "createAlloc: cast incompatible");
451     casted = b.create<memref::CastOp>(loc, memRefType, allocated.getValue());
452   }
453 
454   if (deallocMemref) {
455     // 2. Create memory deallocation.
456     b.setInsertionPoint(allocated.getValue().getParentBlock()->getTerminator());
457     if (failed(createDealloc(b, loc, allocated.getValue(), options)))
458       return failure();
459   }
460 
461   return casted;
462 }
463 
464 /// Create a memref allocation with the given type and dynamic extents.
465 FailureOr<Value>
466 bufferization::createAlloc(OpBuilder &b, Location loc, MemRefType type,
467                            ValueRange dynShape,
468                            const BufferizationOptions &options) {
469   if (options.allocationFn)
470     return (*options.allocationFn)(b, loc, type, dynShape,
471                                    options.bufferAlignment);
472 
473   // Default bufferallocation via AllocOp.
474   Value allocated = b.create<memref::AllocOp>(
475       loc, type, dynShape, b.getI64IntegerAttr(options.bufferAlignment));
476   return allocated;
477 }
478 
479 /// Create a memref allocation with the given type and dynamic extents. May also
480 /// deallocate the memref again.
481 FailureOr<Value>
482 bufferization::createAlloc(OpBuilder &b, Location loc, MemRefType type,
483                            ValueRange dynShape, bool deallocMemref,
484                            const BufferizationOptions &options) {
485   OpBuilder::InsertionGuard g(b);
486 
487   FailureOr<Value> alloc = createAlloc(b, loc, type, dynShape, options);
488   if (failed(alloc))
489     return failure();
490 
491   if (deallocMemref) {
492     // Dealloc at the end of the block.
493     b.setInsertionPoint(alloc.getValue().getParentBlock()->getTerminator());
494     if (failed(createDealloc(b, loc, *alloc, options)))
495       return failure();
496   }
497 
498   return alloc;
499 }
500 
501 /// Create a memref deallocation.
502 LogicalResult
503 bufferization::createDealloc(OpBuilder &b, Location loc, Value allocatedBuffer,
504                              const BufferizationOptions &options) {
505   if (options.deallocationFn)
506     return (*options.deallocationFn)(b, loc, allocatedBuffer);
507 
508   // Default buffer deallocation via DeallocOp.
509   b.create<memref::DeallocOp>(loc, allocatedBuffer);
510   return success();
511 }
512 
513 /// Create a memory copy between two memref buffers.
514 LogicalResult bufferization::createMemCpy(OpBuilder &b, Location loc,
515                                           Value from, Value to,
516                                           const BufferizationOptions &options) {
517   if (options.memCpyFn)
518     return (*options.memCpyFn)(b, loc, from, to);
519 
520   b.create<memref::CopyOp>(loc, from, to);
521   return success();
522 }
523 
524 //===----------------------------------------------------------------------===//
525 // Bufferization-specific BlockAndValueMapping support with debugging.
526 //===----------------------------------------------------------------------===//
527 
528 bool bufferization::isFunctionArgument(Value value) {
529   auto bbArg = value.dyn_cast<BlockArgument>();
530   if (!bbArg)
531     return false;
532   return isa<FuncOp>(bbArg.getOwner()->getParentOp());
533 }
534 
535 MemRefType bufferization::getContiguousMemRefType(ShapedType shapedType,
536                                                   Attribute memorySpace) {
537   MemRefLayoutAttrInterface layout = {};
538   return MemRefType::get(shapedType.getShape(), shapedType.getElementType(),
539                          layout, memorySpace);
540 }
541 
542 BaseMemRefType bufferization::getMemRefType(TensorType tensorType,
543                                             const BufferizationOptions &options,
544                                             MemRefLayoutAttrInterface layout,
545                                             Attribute memorySpace) {
546   // Case 1: Unranked memref type.
547   if (auto unrankedTensorType = tensorType.dyn_cast<UnrankedTensorType>()) {
548     assert(!layout && "UnrankedTensorType cannot have a layout map");
549     return UnrankedMemRefType::get(unrankedTensorType.getElementType(),
550                                    memorySpace);
551   }
552 
553   // Case 2: Ranked memref type with specified layout. If fully dynamic layout
554   // maps are not requested, generate a type with `layout`, which is empty (no
555   // layout map) by default.
556   auto rankedTensorType = tensorType.cast<RankedTensorType>();
557   if (layout || !options.fullyDynamicLayoutMaps) {
558     return MemRefType::get(rankedTensorType.getShape(),
559                            rankedTensorType.getElementType(), layout,
560                            memorySpace);
561   }
562 
563   // Case 3: Ranked memref type with unspecified layout. Choose the most dynamic
564   // one.
565   // TODO: address space decisions to connect with the actual alloc.
566   int64_t dynamicOffset = ShapedType::kDynamicStrideOrOffset;
567   SmallVector<int64_t> dynamicStrides(rankedTensorType.getRank(),
568                                       ShapedType::kDynamicStrideOrOffset);
569   AffineMap stridedLayout = makeStridedLinearLayoutMap(
570       dynamicStrides, dynamicOffset, rankedTensorType.getContext());
571   return MemRefType::get(rankedTensorType.getShape(),
572                          rankedTensorType.getElementType(), stridedLayout,
573                          memorySpace);
574 }
575