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 
13 #include "mlir/IR/Operation.h"
14 
15 namespace mlir {
16 namespace bufferization {
17 class AnalysisState;
18 struct BufferizationStatistics;
19 class OneShotAnalysisState;
20 struct OneShotBufferizationOptions;
21 
22 /// Try to eliminate "tensor.empty" ops inside `op`. This transformation looks
23 /// for subset ops that insert a tensor that originates from a "tensor.empty"
24 /// (as per the reverse use-def chain). Such "tensor.empty" ops are replaced
25 /// with the destination subset.
26 ///
27 /// E.g.:
28 /// %0 = tensor.empty() : tensor<10xf32>
29 /// %1 = linalg.fill ... outs(%0 : tensor<10xf32>)
30 /// %2 = tensor.insert_slice %0 into %t ...
31 ///
32 /// In the above example, the subset op is "tensor.insert_slice". When tracing
33 /// back the reverse use-def chain of a the source, we end up at a
34 /// "tensor.empty" op.
35 LogicalResult eliminateEmptyTensors(RewriterBase &rewriter, Operation *op);
36 
37 /// Try to eliminate "tensor.empty" ops inside `op`.
38 ///
39 /// This function overload accepts an existing `OneShotAnalysisState`, which
40 /// contains in-place bufferization decisions. This overload is useful if an
41 /// existing analysis should be reused for empty tensor elimination.
42 LogicalResult eliminateEmptyTensors(RewriterBase &rewriter, Operation *op,
43  OneShotAnalysisState &state);
44 
45 /// Within the given operation, hoist buffers from loops where possible. See
46 /// "BufferLoopHoistingPass" for more information.
47 void hoistBuffersFromLoops(Operation *op);
48 
49 /// Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
50 /// After applying this transform, the IR can be bufferized without inserting
51 /// additional buffer allocations.
52 LogicalResult insertTensorCopies(Operation *op,
53  const OneShotBufferizationOptions &options,
54  BufferizationStatistics *statistics = nullptr);
55 
56 /// Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
57 /// After applying this transform, the IR can be bufferized without inserting
58 /// additional buffer allocations.
59 LogicalResult insertTensorCopies(Operation *op, const AnalysisState &state);
60 
61 /// Populate patterns to lower tensor.empty ops to bufferization.alloc_tensor
62 /// ops.
63 void populateEmptyTensorToAllocTensorPattern(RewritePatternSet &patterns);
64 
65 } // namespace bufferization
66 } // namespace mlir
67 
68 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_TRANSFORMS_H
static llvm::ManagedStatic< PassManagerOptions > options
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.
LogicalResult eliminateEmptyTensors(RewriterBase &rewriter, Operation *op)
Try to eliminate "tensor.empty" ops inside op.
Include the generated interface declarations.