MLIR 22.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
17namespace mlir {
18namespace bufferization {
19class AnalysisState;
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.
37LogicalResult 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.
65LogicalResult 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.
76LogicalResult insertTensorCopies(Operation *op,
78 const BufferizationState &bufferizationState,
79 BufferizationStatistics *statistics = nullptr);
80
81/// Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
82/// After applying this transform, the IR can be bufferized without inserting
83/// additional buffer allocations.
84LogicalResult insertTensorCopies(Operation *op,
85 const AnalysisState &analysisState,
86 const BufferizationState &bufferizationState);
87
88/// Populate patterns to lower tensor.empty ops to bufferization.alloc_tensor
89/// ops.
91
92} // namespace bufferization
93} // namespace mlir
94
95#endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_TRANSFORMS_H
static llvm::ManagedStatic< PassManagerOptions > options
Base class for generic analysis states.
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...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
State for analysis-enabled bufferization.
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, const BufferizationState &bufferizationState, BufferizationStatistics *statistics=nullptr)
Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
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:47
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:35
Options for analysis-enabled bufferization.