MLIR  17.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"
25 
26 #include <optional>
27 
28 namespace mlir {
29 
30 namespace arith {
31 enum class AtomicRMWKind : uint64_t;
32 class AtomicRMWKindAttr;
33 } // namespace arith
34 
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 dimensions of the given memref value.
63 SmallVector<OpFoldResult> getMixedSizes(OpBuilder &builder, Location loc,
64  Value value);
65 
66 /// Create a rank-reducing SubViewOp @[0 .. 0] with strides [1 .. 1] and
67 /// appropriate sizes (i.e. `memref.getSizes()`) to reduce the rank of `memref`
68 /// to that of `targetShape`.
69 Value createCanonicalRankReducingSubViewOp(OpBuilder &b, Location loc,
70  Value memref,
71  ArrayRef<int64_t> targetShape);
72 } // namespace memref
73 } // namespace mlir
74 
75 //===----------------------------------------------------------------------===//
76 // MemRef Dialect
77 //===----------------------------------------------------------------------===//
78 
79 #include "mlir/Dialect/MemRef/IR/MemRefOpsDialect.h.inc"
80 
81 //===----------------------------------------------------------------------===//
82 // MemRef Dialect Operations
83 //===----------------------------------------------------------------------===//
84 
85 #define GET_OP_CLASSES
86 #include "mlir/Dialect/MemRef/IR/MemRefOps.h.inc"
87 
88 #endif // MLIR_DIALECT_MEMREF_IR_MEMREF_H_
This header declares functions that assit transformations in the MemRef dialect.