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