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