MLIR  21.0.0git
MemRef.h
Go to the documentation of this file.
1 //===- MemRef.h - MemRef dialect --------------------------------*- 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 #ifndef MLIR_DIALECT_MEMREF_IR_MEMREF_H_
10 #define MLIR_DIALECT_MEMREF_IR_MEMREF_H_
11 
15 #include "mlir/IR/Dialect.h"
26 
27 #include <optional>
28 
29 namespace mlir {
30 
31 namespace arith {
32 enum class AtomicRMWKind : uint64_t;
33 class AtomicRMWKindAttr;
34 } // namespace arith
35 
36 class Location;
37 class OpBuilder;
38 
39 raw_ostream &operator<<(raw_ostream &os, const Range &range);
40 
41 /// Return the list of Range (i.e. offset, size, stride). Each Range
42 /// entry contains either the dynamic value or a ConstantIndexOp constructed
43 /// with `b` at location `loc`.
44 SmallVector<Range, 8> getOrCreateRanges(OffsetSizeAndStrideOpInterface op,
45  OpBuilder &b, Location loc);
46 
47 namespace memref {
48 
49 /// This is a common utility used for patterns of the form
50 /// "someop(memref.cast) -> someop". It folds the source of any memref.cast
51 /// into the root operation directly.
52 LogicalResult foldMemRefCast(Operation *op, Value inner = nullptr);
53 
54 /// Return an unranked/ranked tensor type for the given unranked/ranked memref
55 /// type.
56 Type getTensorTypeFromMemRefType(Type type);
57 
58 /// Finds a single dealloc operation for the given allocated value. If there
59 /// are > 1 deallocates for `allocValue`, returns std::nullopt, else returns the
60 /// single deallocate if it exists or nullptr.
61 std::optional<Operation *> findDealloc(Value allocValue);
62 
63 /// Return the dimension of the given memref value.
64 OpFoldResult getMixedSize(OpBuilder &builder, Location loc, Value value,
65  int64_t dim);
66 
67 /// Return the dimensions of the given memref value.
68 SmallVector<OpFoldResult> getMixedSizes(OpBuilder &builder, Location loc,
69  Value value);
70 
71 /// Create a rank-reducing SubViewOp @[0 .. 0] with strides [1 .. 1] and
72 /// appropriate sizes (i.e. `memref.getSizes()`) to reduce the rank of `memref`
73 /// to that of `targetShape`.
74 Value createCanonicalRankReducingSubViewOp(OpBuilder &b, Location loc,
75  Value memref,
76  ArrayRef<int64_t> targetShape);
77 } // namespace memref
78 } // namespace mlir
79 
80 //===----------------------------------------------------------------------===//
81 // MemRef Dialect
82 //===----------------------------------------------------------------------===//
83 
84 #include "mlir/Dialect/MemRef/IR/MemRefOpsDialect.h.inc"
85 
86 //===----------------------------------------------------------------------===//
87 // MemRef Dialect Operations
88 //===----------------------------------------------------------------------===//
89 
90 #define GET_OP_CLASSES
91 #include "mlir/Dialect/MemRef/IR/MemRefOps.h.inc"
92 
93 #endif // MLIR_DIALECT_MEMREF_IR_MEMREF_H_
Include the generated interface declarations.