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