Skip to content

Commit 8b161e9

Browse files
[mlir][memref] NFC - Move utility function declaration from IR/MemRef.h to Utils/MemRefUtils.h
1 parent 0489cfe commit 8b161e9

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed

mlir/include/mlir/Dialect/MemRef/IR/MemRef.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
#ifndef MLIR_DIALECT_MEMREF_IR_MEMREF_H_
1010
#define MLIR_DIALECT_MEMREF_IR_MEMREF_H_
1111

12-
#include "mlir/Bytecode/BytecodeOpInterface.h"
1312
#include "mlir/Dialect/Arith/IR/Arith.h"
13+
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
1414
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
15-
#include "mlir/IR/Dialect.h"
1615
#include "mlir/Interfaces/CallInterfaces.h"
17-
#include "mlir/Interfaces/CastInterfaces.h"
1816
#include "mlir/Interfaces/ControlFlowInterfaces.h"
1917
#include "mlir/Interfaces/CopyOpInterface.h"
2018
#include "mlir/Interfaces/InferTypeOpInterface.h"
@@ -32,48 +30,6 @@ enum class AtomicRMWKind : uint64_t;
3230
class AtomicRMWKindAttr;
3331
} // namespace arith
3432

35-
class Location;
36-
class OpBuilder;
37-
38-
raw_ostream &operator<<(raw_ostream &os, const Range &range);
39-
40-
/// Return the list of Range (i.e. offset, size, stride). Each Range
41-
/// entry contains either the dynamic value or a ConstantIndexOp constructed
42-
/// with `b` at location `loc`.
43-
SmallVector<Range, 8> getOrCreateRanges(OffsetSizeAndStrideOpInterface op,
44-
OpBuilder &b, Location loc);
45-
46-
namespace memref {
47-
48-
/// This is a common utility used for patterns of the form
49-
/// "someop(memref.cast) -> someop". It folds the source of any memref.cast
50-
/// into the root operation directly.
51-
LogicalResult foldMemRefCast(Operation *op, Value inner = nullptr);
52-
53-
/// Return an unranked/ranked tensor type for the given unranked/ranked memref
54-
/// type.
55-
Type getTensorTypeFromMemRefType(Type type);
56-
57-
/// Finds a single dealloc operation for the given allocated value. If there
58-
/// are > 1 deallocates for `allocValue`, returns std::nullopt, else returns the
59-
/// single deallocate if it exists or nullptr.
60-
std::optional<Operation *> findDealloc(Value allocValue);
61-
62-
/// Return the dimension of the given memref value.
63-
OpFoldResult getMixedSize(OpBuilder &builder, Location loc, Value value,
64-
int64_t dim);
65-
66-
/// Return the dimensions of the given memref value.
67-
SmallVector<OpFoldResult> getMixedSizes(OpBuilder &builder, Location loc,
68-
Value value);
69-
70-
/// Create a rank-reducing SubViewOp @[0 .. 0] with strides [1 .. 1] and
71-
/// appropriate sizes (i.e. `memref.getSizes()`) to reduce the rank of `memref`
72-
/// to that of `targetShape`.
73-
Value createCanonicalRankReducingSubViewOp(OpBuilder &b, Location loc,
74-
Value memref,
75-
ArrayRef<int64_t> targetShape);
76-
} // namespace memref
7733
} // namespace mlir
7834

7935
//===----------------------------------------------------------------------===//

mlir/include/mlir/Dialect/MemRef/Utils/MemRefUtils.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,55 @@
1616
#ifndef MLIR_DIALECT_MEMREF_UTILS_MEMREFUTILS_H
1717
#define MLIR_DIALECT_MEMREF_UTILS_MEMREFUTILS_H
1818

19-
#include "mlir/Dialect/MemRef/IR/MemRef.h"
19+
#include "mlir/Interfaces/ViewLikeInterface.h"
20+
#include "mlir/Support/LogicalResult.h"
2021

2122
namespace mlir {
2223

24+
class Location;
2325
class MemRefType;
26+
class OpBuilder;
27+
class Operation;
28+
29+
llvm::raw_ostream &operator<<(raw_ostream &os, const Range &range);
30+
31+
/// Return the list of Range (i.e. offset, size, stride). Each Range
32+
/// entry contains either the dynamic value or a ConstantIndexOp constructed
33+
/// with `b` at location `loc`.
34+
SmallVector<Range, 8> getOrCreateRanges(OffsetSizeAndStrideOpInterface op,
35+
OpBuilder &b, Location loc);
2436

2537
namespace memref {
38+
class ExtractStridedMetadataOp;
39+
40+
/// This is a common utility used for patterns of the form
41+
/// "someop(memref.cast) -> someop". It folds the source of any memref.cast
42+
/// into the root operation directly.
43+
LogicalResult foldMemRefCast(Operation *op, Value inner = nullptr);
44+
45+
/// Return an unranked/ranked tensor type for the given unranked/ranked memref
46+
/// type.
47+
Type getTensorTypeFromMemRefType(Type type);
48+
49+
/// Finds a single dealloc operation for the given allocated value. If there
50+
/// are > 1 deallocates for `allocValue`, returns std::nullopt, else returns
51+
/// the single deallocate if it exists or nullptr.
52+
std::optional<Operation *> findDealloc(Value allocValue);
53+
54+
/// Return the dimension of the given memref value.
55+
OpFoldResult getMixedSize(OpBuilder &builder, Location loc, Value value,
56+
int64_t dim);
57+
58+
/// Return the dimensions of the given memref value.
59+
SmallVector<OpFoldResult> getMixedSizes(OpBuilder &builder, Location loc,
60+
Value value);
61+
62+
/// Create a rank-reducing SubViewOp @[0 .. 0] with strides [1 .. 1] and
63+
/// appropriate sizes (i.e. `memref.getSizes()`) to reduce the rank of
64+
/// `memref` to that of `targetShape`.
65+
Value createCanonicalRankReducingSubViewOp(OpBuilder &b, Location loc,
66+
Value memref,
67+
ArrayRef<int64_t> targetShape);
2668

2769
/// Returns true, if the memref type has static shapes and represents a
2870
/// contiguous chunk of memory.

0 commit comments

Comments
 (0)