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