MLIR  16.0.0git
Bufferization.h
Go to the documentation of this file.
1 //===- Bufferization.h - Bufferization 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_BUFFERIZATION_IR_BUFFERIZATION_H_
10 #define MLIR_DIALECT_BUFFERIZATION_IR_BUFFERIZATION_H_
11 
16 
17 //===----------------------------------------------------------------------===//
18 // Bufferization Dialect
19 //===----------------------------------------------------------------------===//
20 
21 #include "mlir/Dialect/Bufferization/IR/BufferizationOpsDialect.h.inc"
22 
23 //===----------------------------------------------------------------------===//
24 // Bufferization Dialect Operations
25 //===----------------------------------------------------------------------===//
26 
27 #define GET_OP_CLASSES
28 #include "mlir/Dialect/Bufferization/IR/BufferizationOps.h.inc"
29 
30 //===----------------------------------------------------------------------===//
31 // Helper functions
32 //===----------------------------------------------------------------------===//
33 
34 namespace mlir {
35 namespace bufferization {
36 /// Populate `dynamicDims` with tensor::DimOp / memref::DimOp results for all
37 /// dynamic dimensions of the given shaped value.
38 void populateDynamicDimSizes(OpBuilder &b, Location loc, Value shapedValue,
39  SmallVector<Value> &dynamicDims);
40 
41 /// Try to cast the given ranked MemRef-typed value to the given ranked MemRef
42 /// type. Insert a reallocation + copy if it cannot be statically guaranteed
43 /// that a direct cast would be valid.
44 ///
45 /// E.g., when casting from a ranked MemRef type with dynamic layout to a ranked
46 /// MemRef type with static layout, it is not statically known whether the cast
47 /// will succeed or not. Such `memref.cast` ops may fail at runtime. This
48 /// function never generates such casts and conservatively inserts a copy.
49 ///
50 /// This function returns `failure()` in case of unsupported casts. E.g., casts
51 /// with differing element types or memory spaces.
52 FailureOr<Value> castOrReallocMemRefValue(OpBuilder &b, Value value,
53  MemRefType type);
54 
55 /// Try to fold to_memref(to_tensor(x)). If x's type and the result type of the
56 /// to_memref op are different, a memref.cast is needed.
57 LogicalResult foldToMemrefToTensorPair(RewriterBase &rewriter,
58  ToMemrefOp toMemref);
59 
60 } // namespace bufferization
61 } // namespace mlir
62 
63 #endif // MLIR_DIALECT_BUFFERIZATION_IR_BUFFERIZATION_H_
Include the generated interface declarations.
static constexpr const bool value
LogicalResult foldToMemrefToTensorPair(RewriterBase &rewriter, ToMemrefOp toMemref)
Try to fold to_memref(to_tensor(x)).
FailureOr< Value > castOrReallocMemRefValue(OpBuilder &b, Value value, MemRefType type)
Try to cast the given ranked MemRef-typed value to the given ranked MemRef type.
void populateDynamicDimSizes(OpBuilder &b, Location loc, Value shapedValue, SmallVector< Value > &dynamicDims)
Populate dynamicDims with tensor::DimOp / memref::DimOp results for all dynamic dimensions of the giv...