MLIR  19.0.0git
MemRefUtils.h
Go to the documentation of this file.
1 //===- MemRefUtils.h - MemRef transformation utilities ----------*- C++ -*-===//
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 // This header file defines prototypes for various transformation utilities for
10 // the MemRefOps dialect. These are not passes by themselves but are used
11 // either by passes, optimization sequences, or in turn by other transformation
12 // utilities.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef MLIR_DIALECT_MEMREF_UTILS_MEMREFUTILS_H
17 #define MLIR_DIALECT_MEMREF_UTILS_MEMREFUTILS_H
18 
20 
21 namespace mlir {
22 
23 class MemRefType;
24 
25 namespace memref {
26 
27 /// Returns true, if the memref type has static shapes and represents a
28 /// contiguous chunk of memory.
29 bool isStaticShapeAndContiguousRowMajor(MemRefType type);
30 
31 /// For a `memref` with `offset`, `sizes` and `strides`, returns the
32 /// offset and size to use for the linearized `memref`.
33 /// - If the linearization is done for emulating load/stores of
34 /// element type with bitwidth `srcBits` using element type with
35 /// bitwidth `dstBits`, the linearized offset and size are
36 /// scaled down by `dstBits`/`srcBits`.
37 /// - If `indices` is provided, it represents the position in the
38 /// original `memref` being accessed. The method then returns the
39 /// index to use in the linearized `memref`. The linearized index
40 /// is also scaled down by `dstBits`/`srcBits`. If `indices` is not provided
41 /// 0, is returned for the linearized index.
45 };
46 std::pair<LinearizedMemRefInfo, OpFoldResult> getLinearizedMemRefOffsetAndSize(
47  OpBuilder &builder, Location loc, int srcBits, int dstBits,
49  ArrayRef<OpFoldResult> strides, ArrayRef<OpFoldResult> indices = {});
50 
51 /// For a `memref` with `offset` and `sizes`, returns the
52 /// offset and size to use for the linearized `memref`, assuming that
53 /// the strides are computed from a row-major ordering of the sizes;
54 /// - If the linearization is done for emulating load/stores of
55 /// element type with bitwidth `srcBits` using element type with
56 /// bitwidth `dstBits`, the linearized offset and size are
57 /// scaled down by `dstBits`/`srcBits`.
58 LinearizedMemRefInfo
59 getLinearizedMemRefOffsetAndSize(OpBuilder &builder, Location loc, int srcBits,
60  int dstBits, OpFoldResult offset,
62 
63 // Track temporary allocations that are never read from. If this is the case
64 // it means both the allocations and associated stores can be removed.
65 void eraseDeadAllocAndStores(RewriterBase &rewriter, Operation *parentOp);
66 
67 } // namespace memref
68 } // namespace mlir
69 
70 #endif // MLIR_DIALECT_MEMREF_UTILS_MEMREFUTILS_H
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:209
This class represents a single result from folding an operation.
Definition: OpDefinition.h:268
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:400
void eraseDeadAllocAndStores(RewriterBase &rewriter, Operation *parentOp)
std::pair< LinearizedMemRefInfo, OpFoldResult > getLinearizedMemRefOffsetAndSize(OpBuilder &builder, Location loc, int srcBits, int dstBits, OpFoldResult offset, ArrayRef< OpFoldResult > sizes, ArrayRef< OpFoldResult > strides, ArrayRef< OpFoldResult > indices={})
Definition: MemRefUtils.cpp:50
bool isStaticShapeAndContiguousRowMajor(MemRefType type)
Returns true, if the memref type has static shapes and represents a contiguous chunk of memory.
Definition: MemRefUtils.cpp:22
Include the generated interface declarations.
For a memref with offset, sizes and strides, returns the offset and size to use for the linearized me...
Definition: MemRefUtils.h:42