MLIR  17.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
34 FailureOr<ForOp> pipelineForLoop(RewriterBase &rewriter, ForOp forOp,
35  const PipeliningOption &options);
36 
37 // TODO: such patterns should be auto-generated.
39 public:
41  MLIRContext *context)
42  : OpRewritePattern<ForOp>(context), options(options) {}
44  PatternRewriter &rewriter) const override {
45  return returningMatchAndRewrite(forOp, rewriter);
46  }
47 
49  PatternRewriter &rewriter) const {
50  return pipelineForLoop(rewriter, forOp, options);
51  }
52 
53 protected:
55 };
56 
57 } // namespace scf
58 } // namespace mlir
59 
60 #endif // MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
static llvm::ManagedStatic< PassManagerOptions > options
This class provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Definition: PatternMatch.h:700
ForLoopPipeliningPattern(const PipeliningOption &options, MLIRContext *context)
Definition: Patterns.h:40
LogicalResult matchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const override
Definition: Patterns.h:43
FailureOr< ForOp > returningMatchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const
Definition: Patterns.h:48
FailureOr< ForOp > pipelineForLoop(RewriterBase &rewriter, ForOp forOp, const PipeliningOption &options)
Generate a pipelined version of the scf.for loop based on the schedule given as option.
This header declares functions that assit transformations in the MemRef dialect.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
Definition: PatternMatch.h:357
Options to dictate how loops should be pipelined.
Definition: Transforms.h:130