MLIR 22.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
15
16namespace mlir {
17
18class ConversionTarget;
19class TypeConverter;
20
21namespace scf {
22
23// TODO: such patterns should be auto-generated.
25public:
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
39protected:
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,
55
56/// Similar to `populateSCFStructuralTypeConversionsAndLegality` but does not
57/// populate the conversion target.
60 PatternBenefit benefit = 1);
61
62/// Updates the ConversionTarget with dynamic legality of SCF operations based
63/// on the provided type converter.
65 const TypeConverter &typeConverter, ConversionTarget &target);
66
67/// Populate patterns for SCF software pipelining transformation. See the
68/// ForLoopPipeliningPattern for the transformation details.
71
72/// Populate patterns for canonicalizing operations inside SCF loop bodies.
73/// At the moment, only affine.min/max computations with iteration variables,
74/// loop bounds and loop steps are canonicalized.
76
77/// Populate patterns to uplift `scf.while` ops to `scf.for`.
78/// Uplifitng expects a specific ops pattern:
79/// * `before` block consisting of single arith.cmp op
80/// * `after` block containing arith.addi
82
83/// Populate patterns to rotate `scf.while` ops, constructing `do-while` loops
84/// from `while` loops.
86} // namespace scf
87} // namespace mlir
88
89#endif // MLIR_DIALECT_SCF_TRANSFORMS_PATTERNS_H
static llvm::ManagedStatic< PassManagerOptions > options
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
FailureOr< ForOp > returningMatchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const
Definition Patterns.h:34
ForLoopPipeliningPattern(const PipeliningOption &options, MLIRContext *context)
Definition Patterns.h:26
LogicalResult matchAndRewrite(ForOp forOp, PatternRewriter &rewriter) const override
Definition Patterns.h:29
void populateSCFStructuralTypeConversions(const TypeConverter &typeConverter, RewritePatternSet &patterns, PatternBenefit benefit=1)
Similar to populateSCFStructuralTypeConversionsAndLegality but does not populate the conversion targe...
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 populateSCFStructuralTypeConversionsAndLegality(const TypeConverter &typeConverter, RewritePatternSet &patterns, ConversionTarget &target, PatternBenefit benefit=1)
Populates patterns for SCF structural type conversions and sets up the provided ConversionTarget with...
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 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(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Options to dictate how loops should be pipelined.
Definition Transforms.h:129