MLIR  20.0.0git
Transforms.h
Go to the documentation of this file.
1 //===- Transforms.h - Bufferization and related transforms ------*- 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_TRANSFORMS_TRANSFORMS_H
10 #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_TRANSFORMS_H
11 
14 #include "mlir/IR/Operation.h"
16 
17 namespace mlir {
18 namespace bufferization {
19 class AnalysisState;
20 struct BufferizationStatistics;
21 class OneShotAnalysisState;
22 struct OneShotBufferizationOptions;
23 
24 /// Try to eliminate "tensor.empty" ops inside `op`. This transformation looks
25 /// for subset ops that insert a tensor that originates from a "tensor.empty"
26 /// (as per the reverse use-def chain). Such "tensor.empty" ops are replaced
27 /// with the destination subset.
28 ///
29 /// E.g.:
30 /// %0 = tensor.empty() : tensor<10xf32>
31 /// %1 = linalg.fill ... outs(%0 : tensor<10xf32>)
32 /// %2 = tensor.insert_slice %0 into %t ...
33 ///
34 /// In the above example, the subset op is "tensor.insert_slice". When tracing
35 /// back the reverse use-def chain of a the source, we end up at a
36 /// "tensor.empty" op.
37 LogicalResult eliminateEmptyTensors(RewriterBase &rewriter, Operation *op);
38 
39 /// A function type that defines a callback to control the construction
40 /// of the subset extraction of the `SubsetInsertionOpInterface`.
41 /// The subset extraction value can be used as a replacement for the
42 /// `emptyTensorOp` value which is being consumed by `user`, failing
43 /// of building such a value should be indicated with an empty value.
44 /// This function should guarantee the legality of the replacement,
45 /// i.e. the replacement should dominate the user of the `emptyTensorOp`
46 /// being eliminated.
48  std::function<Value(RewriterBase &, SubsetInsertionOpInterface,
49  tensor::EmptyOp emptyTensorOp, Operation *user)>;
50 
51 /// This method builds and returns a subset extraction value for the
52 /// destination tensor that the given `op` inserts into.
53 /// It returns a value which should replace the `emptyTensorOp` use
54 /// that is being consumed by `user`.
55 /// If no such a value found it will return an empty Value.
57  SubsetInsertionOpInterface op,
58  tensor::EmptyOp emptyTensorOp, Operation *user);
59 
60 /// Try to eliminate "tensor.empty" ops inside `op`.
61 ///
62 /// This function overload accepts an existing `OneShotAnalysisState`, which
63 /// contains in-place bufferization decisions. This overload is useful if an
64 /// existing analysis should be reused for empty tensor elimination.
65 LogicalResult eliminateEmptyTensors(
66  RewriterBase &rewriter, Operation *op, OneShotAnalysisState &state,
68 
69 /// Within the given operation, hoist buffers from loops where possible. See
70 /// "BufferLoopHoistingPass" for more information.
72 
73 /// Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
74 /// After applying this transform, the IR can be bufferized without inserting
75 /// additional buffer allocations.
76 LogicalResult insertTensorCopies(Operation *op,
78  BufferizationStatistics *statistics = nullptr);
79 
80 /// Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
81 /// After applying this transform, the IR can be bufferized without inserting
82 /// additional buffer allocations.
83 LogicalResult insertTensorCopies(Operation *op, const AnalysisState &state);
84 
85 /// Populate patterns to lower tensor.empty ops to bufferization.alloc_tensor
86 /// ops.
88 
89 } // namespace bufferization
90 } // namespace mlir
91 
92 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_TRANSFORMS_H
static llvm::ManagedStatic< PassManagerOptions > options
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
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
AnalysisState provides a variety of helper functions for dealing with tensor values.
State for analysis-enabled bufferization.
std::function< Value(RewriterBase &, SubsetInsertionOpInterface, tensor::EmptyOp emptyTensorOp, Operation *user)> ControlBuildSubsetExtractionFn
A function type that defines a callback to control the construction of the subset extraction of the S...
Definition: Transforms.h:49
void hoistBuffersFromLoops(Operation *op)
Within the given operation, hoist buffers from loops where possible.
void populateEmptyTensorToAllocTensorPattern(RewritePatternSet &patterns)
Populate patterns to lower tensor.empty ops to bufferization.alloc_tensor ops.
LogicalResult insertTensorCopies(Operation *op, const OneShotBufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
Value buildSubsetExtraction(RewriterBase &rewriter, SubsetInsertionOpInterface op, tensor::EmptyOp emptyTensorOp, Operation *user)
This method builds and returns a subset extraction value for the destination tensor that the given op...
LogicalResult eliminateEmptyTensors(RewriterBase &rewriter, Operation *op)
Try to eliminate "tensor.empty" ops inside op.
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
Bufferization statistics for debugging.
Definition: Bufferize.h:34
Options for analysis-enabled bufferization.