MLIR  19.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) {}
30  PatternRewriter &rewriter) const override {
31  return returningMatchAndRewrite(forOp, rewriter);
32  }
33 
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  TypeConverter &typeConverter, RewritePatternSet &patterns,
54  ConversionTarget &target);
55 
56 /// Similar to `populateSCFStructuralTypeConversionsAndLegality` but does not
57 /// populate the conversion target.
59  RewritePatternSet &patterns);
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  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 } // namespace scf
83 } // namespace mlir
84 
85 #endif // MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
static llvm::ManagedStatic< PassManagerOptions > options
This class describes a specific conversion target.
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:785
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 populateSCFLoopPipeliningPatterns(RewritePatternSet &patterns, const PipeliningOption &options)
Populate patterns for SCF software pipelining transformation.
void populateSCFStructuralTypeConversionsAndLegality(TypeConverter &typeConverter, RewritePatternSet &patterns, ConversionTarget &target)
Populates patterns for SCF structural type conversions and sets up the provided ConversionTarget with...
void populateSCFStructuralOneToNTypeConversions(TypeConverter &typeConverter, RewritePatternSet &patterns)
Populates the provided pattern set with patterns that do 1:N type conversions on (some) SCF ops.
void populateSCFForLoopCanonicalizationPatterns(RewritePatternSet &patterns)
Populate patterns for canonicalizing operations inside SCF loop bodies.
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 populateSCFStructuralTypeConversions(TypeConverter &typeConverter, RewritePatternSet &patterns)
Similar to populateSCFStructuralTypeConversionsAndLegality but does not populate the conversion targe...
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.
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:358
Options to dictate how loops should be pipelined.
Definition: Transforms.h:113