MLIR  16.0.0git
Patterns.h
Go to the documentation of this file.
1 //===- Patterns.h - SCF dialect rewrite patterns ----------------*- 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_SCF_TRANSFORMS_PATTERNS_H
10 #define MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
11 
14 #include "mlir/IR/PatternMatch.h"
15 
16 namespace mlir {
17 namespace scf {
18 /// Generate a pipelined version of the scf.for loop based on the schedule given
19 /// as option. This applies the mechanical transformation of changing the loop
20 /// and generating the prologue/epilogue for the pipelining and doesn't make any
21 /// decision regarding the schedule.
22 /// Based on the options the loop is split into several stages.
23 /// The transformation assumes that the scheduling given by user is valid.
24 /// For example if we break a loop into 3 stages named S0, S1, S2 we would
25 /// generate the following code with the number in parenthesis as the iteration
26 /// index:
27 /// S0(0) // Prologue
28 /// S0(1) S1(0) // Prologue
29 /// scf.for %I = %C0 to %N - 2 {
30 /// S0(I+2) S1(I+1) S2(I) // Pipelined kernel
31 /// }
32 /// S1(N) S2(N-1) // Epilogue
33 /// S2(N) // Epilogue
35 public:
37  MLIRContext *context)
38  : OpRewritePattern<ForOp>(context), options(options) {}
40  PatternRewriter &rewriter) const override {
41  return returningMatchAndRewrite(forOp, rewriter);
42  }
43 
45  PatternRewriter &rewriter) const;
46 
47 protected:
49 };
50 
51 } // namespace scf
52 } // namespace mlir
53 
54 #endif // MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
Include the generated interface declarations.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Definition: PatternMatch.h:600
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
LogicalResult matchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const override
Definition: Patterns.h:39
This class provides support for representing a failure result, or a valid value of type T...
Definition: LogicalResult.h:78
Generate a pipelined version of the scf.for loop based on the schedule given as option.
Definition: Patterns.h:34
FailureOr< ForOp > returningMatchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const
ForLoopPipeliningPattern(const PipeliningOption &options, MLIRContext *context)
Definition: Patterns.h:36
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
Definition: PatternMatch.h:355
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
Options to dictate how loops should be pipelined.
Definition: Transforms.h:124