MLIR  20.0.0git
Passes.h
Go to the documentation of this file.
1 //===- Passes.h - Pass Entrypoints ------------------------------*- 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 // This header file defines a set of transforms specific for the AffineOps
10 // dialect.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_AFFINE_PASSES_H
15 #define MLIR_DIALECT_AFFINE_PASSES_H
16 
17 #include "mlir/Pass/Pass.h"
18 #include <limits>
19 
20 namespace mlir {
21 
22 namespace func {
23 class FuncOp;
24 } // namespace func
25 
26 namespace affine {
27 class AffineForOp;
28 
29 /// Fusion mode to attempt. The default mode `Greedy` does both
30 /// producer-consumer and sibling fusion.
32 
33 #define GEN_PASS_DECL
34 #include "mlir/Dialect/Affine/Passes.h.inc"
35 
36 /// Creates a simplification pass for affine structures (maps and sets). In
37 /// addition, this pass also normalizes memrefs to have the trivial (identity)
38 /// layout map.
39 std::unique_ptr<OperationPass<func::FuncOp>>
41 
42 /// Creates a loop invariant code motion pass that hoists loop invariant
43 /// operations out of affine loops.
44 std::unique_ptr<OperationPass<func::FuncOp>>
46 
47 /// Creates a pass to convert all parallel affine.for's into 1-d affine.parallel
48 /// ops.
49 std::unique_ptr<OperationPass<func::FuncOp>> createAffineParallelizePass();
50 
51 /// Apply normalization transformations to affine loop-like ops. If
52 /// `promoteSingleIter` is true, single iteration loops are promoted (i.e., the
53 /// loop is replaced by its loop body).
54 std::unique_ptr<OperationPass<func::FuncOp>>
55 createAffineLoopNormalizePass(bool promoteSingleIter = false);
56 
57 /// Performs packing (or explicit copying) of accessed memref regions into
58 /// buffers in the specified faster memory space through either pointwise copies
59 /// or DMA operations.
60 std::unique_ptr<OperationPass<func::FuncOp>> createAffineDataCopyGenerationPass(
61  unsigned slowMemorySpace, unsigned fastMemorySpace,
62  unsigned tagMemorySpace = 0, int minDmaTransferSize = 1024,
63  uint64_t fastMemCapacityBytes = std::numeric_limits<uint64_t>::max());
64 /// Overload relying on pass options for initialization.
65 std::unique_ptr<OperationPass<func::FuncOp>>
67 
68 /// Creates a pass to replace affine memref accesses by scalars using store to
69 /// load forwarding and redundant load elimination; consequently also eliminate
70 /// dead allocs.
71 std::unique_ptr<OperationPass<func::FuncOp>>
73 
74 /// Creates a pass that transforms perfectly nested loops with independent
75 /// bounds into a single loop.
76 std::unique_ptr<OperationPass<func::FuncOp>> createLoopCoalescingPass();
77 
78 /// Creates a loop fusion pass which fuses affine loop nests at the top-level of
79 /// the operation the pass is created on according to the type of fusion
80 /// specified in `fusionMode`. Buffers of size less than or equal to
81 /// `localBufSizeThreshold` are promoted to memory space `fastMemorySpace`.
82 std::unique_ptr<Pass>
83 createLoopFusionPass(unsigned fastMemorySpace = 0,
84  uint64_t localBufSizeThreshold = 0,
85  bool maximalFusion = false,
86  enum FusionMode fusionMode = FusionMode::Greedy);
87 
88 /// Creates a pass to perform tiling on loop nests.
89 std::unique_ptr<OperationPass<func::FuncOp>>
90 createLoopTilingPass(uint64_t cacheSizeBytes);
91 /// Overload relying on pass options for initialization.
92 std::unique_ptr<OperationPass<func::FuncOp>> createLoopTilingPass();
93 
94 /// Creates a loop unrolling pass with the provided parameters.
95 /// 'getUnrollFactor' is a function callback for clients to supply a function
96 /// that computes an unroll factor - the callback takes precedence over unroll
97 /// factors supplied through other means. If -1 is passed as the unrollFactor
98 /// and no callback is provided, anything passed from the command-line (if at
99 /// all) or the default unroll factor is used (LoopUnroll:kDefaultUnrollFactor).
100 std::unique_ptr<OperationPass<func::FuncOp>> createLoopUnrollPass(
101  int unrollFactor = -1, bool unrollUpToFactor = false,
102  bool unrollFull = false,
103  const std::function<unsigned(AffineForOp)> &getUnrollFactor = nullptr);
104 
105 /// Creates a loop unroll jam pass to unroll jam by the specified factor. A
106 /// factor of -1 lets the pass use the default factor or the one on the command
107 /// line if provided.
108 std::unique_ptr<OperationPass<func::FuncOp>>
109 createLoopUnrollAndJamPass(int unrollJamFactor = -1);
110 
111 /// Creates a pass to pipeline explicit movement of data across levels of the
112 /// memory hierarchy.
113 std::unique_ptr<OperationPass<func::FuncOp>> createPipelineDataTransferPass();
114 
115 /// Creates a pass to expand affine index operations into more fundamental
116 /// operations (not necessarily restricted to Affine dialect).
117 std::unique_ptr<Pass> createAffineExpandIndexOpsPass();
118 
119 //===----------------------------------------------------------------------===//
120 // Registration
121 //===----------------------------------------------------------------------===//
122 
123 /// Generate the code for registering passes.
124 #define GEN_PASS_REGISTRATION
125 #include "mlir/Dialect/Affine/Passes.h.inc"
126 
127 } // namespace affine
128 } // namespace mlir
129 
130 #endif // MLIR_DIALECT_AFFINE_PASSES_H
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
std::unique_ptr< OperationPass< func::FuncOp > > createAffineScalarReplacementPass()
Creates a pass to replace affine memref accesses by scalars using store to load forwarding and redund...
std::unique_ptr< OperationPass< func::FuncOp > > createAffineLoopInvariantCodeMotionPass()
Creates a loop invariant code motion pass that hoists loop invariant operations out of affine loops.
std::unique_ptr< OperationPass< func::FuncOp > > createLoopCoalescingPass()
Creates a pass that transforms perfectly nested loops with independent bounds into a single loop.
std::unique_ptr< OperationPass< func::FuncOp > > createAffineLoopNormalizePass(bool promoteSingleIter=false)
Apply normalization transformations to affine loop-like ops.
std::unique_ptr< OperationPass< func::FuncOp > > createAffineDataCopyGenerationPass(unsigned slowMemorySpace, unsigned fastMemorySpace, unsigned tagMemorySpace=0, int minDmaTransferSize=1024, uint64_t fastMemCapacityBytes=std::numeric_limits< uint64_t >::max())
Performs packing (or explicit copying) of accessed memref regions into buffers in the specified faste...
std::unique_ptr< OperationPass< func::FuncOp > > createAffineParallelizePass()
Creates a pass to convert all parallel affine.for's into 1-d affine.parallel ops.
std::unique_ptr< Pass > createLoopFusionPass(unsigned fastMemorySpace=0, uint64_t localBufSizeThreshold=0, bool maximalFusion=false, enum FusionMode fusionMode=FusionMode::Greedy)
Creates a loop fusion pass which fuses affine loop nests at the top-level of the operation the pass i...
FusionMode
Fusion mode to attempt.
Definition: Passes.h:31
@ ProducerConsumer
Definition: Passes.h:31
std::unique_ptr< OperationPass< func::FuncOp > > createLoopTilingPass(uint64_t cacheSizeBytes)
Creates a pass to perform tiling on loop nests.
Definition: LoopTiling.cpp:68
std::unique_ptr< Pass > createAffineExpandIndexOpsPass()
Creates a pass to expand affine index operations into more fundamental operations (not necessarily re...
std::unique_ptr< OperationPass< func::FuncOp > > createSimplifyAffineStructuresPass()
Creates a simplification pass for affine structures (maps and sets).
std::unique_ptr< OperationPass< func::FuncOp > > createPipelineDataTransferPass()
Creates a pass to pipeline explicit movement of data across levels of the memory hierarchy.
std::unique_ptr< OperationPass< func::FuncOp > > createLoopUnrollAndJamPass(int unrollJamFactor=-1)
Creates a loop unroll jam pass to unroll jam by the specified factor.
std::unique_ptr< OperationPass< func::FuncOp > > createLoopUnrollPass(int unrollFactor=-1, bool unrollUpToFactor=false, bool unrollFull=false, const std::function< unsigned(AffineForOp)> &getUnrollFactor=nullptr)
Creates a loop unrolling pass with the provided parameters.
Definition: LoopUnroll.cpp:148
Include the generated interface declarations.