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