-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathAffineFullUnrollPatternRewrite.cpp
More file actions
45 lines (38 loc) · 1.68 KB
/
AffineFullUnrollPatternRewrite.cpp
File metadata and controls
45 lines (38 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "lib/Transform/Affine/AffineFullUnrollPatternRewrite.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/include/mlir/Pass/Pass.h"
namespace mlir {
namespace tutorial {
#define GEN_PASS_DEF_AFFINEFULLUNROLLPATTERNREWRITE
#include "lib/Transform/Affine/Passes.h.inc"
using mlir::affine::AffineForOp;
using mlir::affine::loopUnrollFull;
// A pattern that matches on AffineForOp and unrolls it.
struct AffineFullUnrollPattern : public OpRewritePattern<AffineForOp> {
AffineFullUnrollPattern(mlir::MLIRContext *context)
: OpRewritePattern<AffineForOp>(context, /*benefit=*/1) {}
LogicalResult matchAndRewrite(AffineForOp op,
PatternRewriter &rewriter) const override {
// This is technically not allowed, since in a RewritePattern all
// modifications to the IR are supposed to go through the `rewriter` arg,
// but it works for our limited test cases.
return loopUnrollFull(op);
}
};
// A pass that invokes the pattern rewrite engine.
struct AffineFullUnrollPatternRewrite
: impl::AffineFullUnrollPatternRewriteBase<AffineFullUnrollPatternRewrite> {
using AffineFullUnrollPatternRewriteBase::AffineFullUnrollPatternRewriteBase;
void runOnOperation() {
mlir::RewritePatternSet patterns(&getContext());
patterns.add<AffineFullUnrollPattern>(&getContext());
// One could use GreedyRewriteConfig here to slightly tweak the behavior of
// the pattern application.
(void)applyPatternsGreedily(getOperation(), std::move(patterns));
}
};
} // namespace tutorial
} // namespace mlir