MLIR  20.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 
18 class ConversionTarget;
19 class TypeConverter;
20 
21 namespace scf {
22 
23 // TODO: such patterns should be auto-generated.
25 public:
27  MLIRContext *context)
28  : OpRewritePattern<ForOp>(context), options(options) {}
29  LogicalResult matchAndRewrite(ForOp forOp,
30  PatternRewriter &rewriter) const override {
31  return returningMatchAndRewrite(forOp, rewriter);
32  }
33 
34  FailureOr<ForOp> returningMatchAndRewrite(ForOp forOp,
35  PatternRewriter &rewriter) const {
36  return pipelineForLoop(rewriter, forOp, options);
37  }
38 
39 protected:
41 };
42 
43 /// Populates patterns for SCF structural type conversions and sets up the
44 /// provided ConversionTarget with the appropriate legality configuration for
45 /// the ops to get converted properly.
46 ///
47 /// A "structural" type conversion is one where the underlying ops are
48 /// completely agnostic to the actual types involved and simply need to update
49 /// their types. An example of this is scf.if -- the scf.if op and the
50 /// corresponding scf.yield ops need to update their types accordingly to the
51 /// TypeConverter, but otherwise don't care what type conversions are happening.
53  const TypeConverter &typeConverter, RewritePatternSet &patterns,
54  ConversionTarget &target);
55 
56 /// Similar to `populateSCFStructuralTypeConversionsAndLegality` but does not
57 /// populate the conversion target.
58 void populateSCFStructuralTypeConversions(const TypeConverter &typeConverter,
60 
61 /// Updates the ConversionTarget with dynamic legality of SCF operations based
62 /// on the provided type converter.
64  const TypeConverter &typeConverter, ConversionTarget &target);
65 
66 /// Populates the provided pattern set with patterns that do 1:N type
67 /// conversions on (some) SCF ops. This is intended to be used with
68 /// applyPartialOneToNConversion.
70  const TypeConverter &typeConverter, RewritePatternSet &patterns);
71 
72 /// Populate patterns for SCF software pipelining transformation. See the
73 /// ForLoopPipeliningPattern for the transformation details.
75  const PipeliningOption &options);
76 
77 /// Populate patterns for canonicalizing operations inside SCF loop bodies.
78 /// At the moment, only affine.min/max computations with iteration variables,
79 /// loop bounds and loop steps are canonicalized.
81 
82 /// Populate patterns to uplift `scf.while` ops to `scf.for`.
83 /// Uplifitng expects a specific ops pattern:
84 /// * `before` block consisting of single arith.cmp op
85 /// * `after` block containing arith.addi
87 
88 /// Populate patterns to rotate `scf.while` ops, constructing `do-while` loops
89 /// from `while` loops.
91 } // namespace scf
92 } // namespace mlir
93 
94 #endif // MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
static llvm::ManagedStatic< PassManagerOptions > options
This class describes a specific conversion target.
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:791
Type conversion class.
ForLoopPipeliningPattern(const PipeliningOption &options, MLIRContext *context)
Definition: Patterns.h:26
LogicalResult matchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const override
Definition: Patterns.h:29
FailureOr< ForOp > returningMatchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const
Definition: Patterns.h:34
void populateSCFStructuralTypeConversionsAndLegality(const TypeConverter &typeConverter, RewritePatternSet &patterns, ConversionTarget &target)
Populates patterns for SCF structural type conversions and sets up the provided ConversionTarget with...
void populateSCFLoopPipeliningPatterns(RewritePatternSet &patterns, const PipeliningOption &options)
Populate patterns for SCF software pipelining transformation.
void populateSCFRotateWhileLoopPatterns(RewritePatternSet &patterns)
Populate patterns to rotate scf.while ops, constructing do-while loops from while loops.
void populateUpliftWhileToForPatterns(RewritePatternSet &patterns)
Populate patterns to uplift scf.while ops to scf.for.
void populateSCFStructuralTypeConversions(const TypeConverter &typeConverter, RewritePatternSet &patterns)
Similar to populateSCFStructuralTypeConversionsAndLegality but does not populate the conversion targe...
void populateSCFForLoopCanonicalizationPatterns(RewritePatternSet &patterns)
Populate patterns for canonicalizing operations inside SCF loop bodies.
void populateSCFStructuralOneToNTypeConversions(const TypeConverter &typeConverter, RewritePatternSet &patterns)
Populates the provided pattern set with patterns that do 1:N type conversions on (some) SCF ops.
FailureOr< ForOp > pipelineForLoop(RewriterBase &rewriter, ForOp forOp, const PipeliningOption &options, bool *modifiedIR=nullptr)
Generate a pipelined version of the scf.for loop based on the schedule given as option.
void populateSCFStructuralTypeConversionTarget(const TypeConverter &typeConverter, ConversionTarget &target)
Updates the ConversionTarget with dynamic legality of SCF operations based on the provided type conve...
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
Definition: PatternMatch.h:358
Options to dictate how loops should be pipelined.
Definition: Transforms.h:123