MLIR  19.0.0git
Bufferize.h
Go to the documentation of this file.
1 //===- Bufferize.h - Bufferization Utilities --------------------*- 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 // We use the term "bufferize" to mean conversion from tensor types to
10 // memref types.
11 //
12 // Generally speaking, for each op that operates on tensor types, the
13 // `BufferizableOpInterface` needs to be implemented. This file contains the
14 // bufferization driver that is responsible for bufferizing the ops in the right
15 // order, etc.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERIZE_H
20 #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERIZE_H
21 
23 
24 namespace mlir {
25 namespace bufferization {
26 
27 class AnalysisState;
28 struct BufferizationOptions;
29 class OpFilter;
30 
31 /// Bufferization statistics for debugging. These can be printed after running
32 /// the OneShotBufferizePass with `-mlir-pass-statistics`. See the pass
33 /// definition for more details.
35  int64_t numBufferAlloc = 0;
36  int64_t numBufferDealloc = 0;
37  int64_t numTensorInPlace = 0;
38  int64_t numTensorOutOfPlace = 0;
39 };
40 
41 /// A helper type converter class that automatically populates the relevant
42 /// materializations and type conversions for bufferization.
44 public:
46 };
47 
48 /// Marks ops used by bufferization for type conversion materializations as
49 /// "legal" in the given ConversionTarget.
50 ///
51 /// This function should be called by all bufferization passes using
52 /// BufferizeTypeConverter so that materializations work properly. One exception
53 /// is bufferization passes doing "full" conversions, where it can be desirable
54 /// for even the materializations to remain illegal so that they are eliminated,
55 /// such as via the patterns in
56 /// populateEliminateBufferizeMaterializationsPatterns.
58 
59 /// Populate patterns to eliminate bufferize materializations.
60 ///
61 /// In particular, these are the tensor_load/buffer_cast ops.
63  BufferizeTypeConverter &typeConverter, RewritePatternSet &patterns);
64 
65 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
66 ///
67 /// Note: This function does not resolve read-after-write conflicts. Use this
68 /// function only if it is guaranteed that the input IR can bufferize without
69 /// additional buffer copies or set "options.copyBeforeWrite = true". The
70 /// general bufferization entry point is `runOneShotBufferize`.
72  BufferizationStatistics *statistics = nullptr);
73 
74 /// Bufferize the signature of `block` and its callers (i.e., ops that have the
75 /// given block as a successor). All block argument types are changed to memref
76 /// types. All corresponding operands of all callers are wrapped in
77 /// bufferization.to_memref ops. All uses of bufferized tensor block arguments
78 /// are wrapped in bufferization.to_tensor ops.
79 ///
80 /// It is expected that all callers implement the `BranchOpInterface`.
81 /// Otherwise, this function will fail. The `BranchOpInterface` is used to query
82 /// the range of operands that are forwarded to this block.
83 ///
84 /// It is expected that the parent op of this block implements the
85 /// `BufferizableOpInterface`. The buffer types of tensor block arguments are
86 /// computed with `BufferizableOpIntercace::getBufferType`.
89 
90 /// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
91 /// old (deprecated) partial, dialect conversion-based bufferization passes. A
92 /// copy will be inserted before every buffer write.
94 
95 } // namespace bufferization
96 } // namespace mlir
97 
98 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERIZE_H
static llvm::ManagedStatic< PassManagerOptions > options
Block represents an ordered list of Operations.
Definition: Block.h:30
This class describes a specific conversion target.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:400
Type conversion class.
A helper type converter class that automatically populates the relevant materializations and type con...
Definition: Bufferize.h:43
BufferizeTypeConverter()
Registers conversions into BufferizeTypeConverter.
Definition: Bufferize.cpp:53
void populateEliminateBufferizeMaterializationsPatterns(BufferizeTypeConverter &typeConverter, RewritePatternSet &patterns)
Populate patterns to eliminate bufferize materializations.
Definition: Bufferize.cpp:130
void populateBufferizeMaterializationLegality(ConversionTarget &target)
Marks ops used by bufferization for type conversion materializations as "legal" in the given Conversi...
Definition: Bufferize.cpp:93
LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
Definition: Bufferize.cpp:439
LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter, const BufferizationOptions &options)
Bufferize the signature of block and its callers (i.e., ops that have the given block as a successor)...
Definition: Bufferize.cpp:557
BufferizationOptions getPartialBufferizationOptions()
Return BufferizationOptions such that the bufferizeOp behaves like the old (deprecated) partial,...
Definition: Bufferize.cpp:643
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
Options for BufferizableOpInterface-based bufferization.
Bufferization statistics for debugging.
Definition: Bufferize.h:34