Skip to content

Commit e062c93

Browse files
committed
move test pass
1 parent f619c6f commit e062c93

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

mlir/include/mlir/Dialect/SCF/Transforms/Passes.td

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,4 @@ def SCFForToWhileLoop : Pass<"scf-for-to-while"> {
154154
}];
155155
}
156156

157-
def TestSCFUpliftWhileToFor : Pass<"test-scf-uplift-while-to-for"> {
158-
let summary = "Uplift scf.while ops to scf.for";
159-
let description = [{
160-
This pass tries to uplift `scf.while` ops to `scf.for` if they have a
161-
compatible form. `scf.while` are left unchanged if uplifting is not
162-
possible.
163-
164-
This pass expects a specific ops pattern:
165-
* `before` block consisting of single arith.cmp op
166-
* `after` block containing arith.addi
167-
}];
168-
}
169-
170-
171157
#endif // MLIR_DIALECT_SCF_PASSES

mlir/lib/Dialect/SCF/Transforms/UpliftWhileToFor.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#include "mlir/Dialect/SCF/Transforms/Patterns.h"
1818
#include "mlir/IR/Dominance.h"
1919
#include "mlir/IR/PatternMatch.h"
20-
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21-
22-
namespace mlir {
23-
#define GEN_PASS_DEF_TESTSCFUPLIFTWHILETOFOR
24-
#include "mlir/Dialect/SCF/Transforms/Passes.h.inc"
25-
} // namespace mlir
2620

2721
using namespace mlir;
2822

@@ -35,20 +29,6 @@ struct UpliftWhileOp : public OpRewritePattern<scf::WhileOp> {
3529
return upliftWhileToForLoop(rewriter, loop);
3630
}
3731
};
38-
39-
struct TestSCFUpliftWhileToFor final
40-
: impl::TestSCFUpliftWhileToForBase<TestSCFUpliftWhileToFor> {
41-
using TestSCFUpliftWhileToForBase::TestSCFUpliftWhileToForBase;
42-
43-
void runOnOperation() override {
44-
Operation *op = getOperation();
45-
MLIRContext *ctx = op->getContext();
46-
RewritePatternSet patterns(ctx);
47-
mlir::scf::populateUpliftWhileToForPatterns(patterns);
48-
if (failed(applyPatternsAndFoldGreedily(op, std::move(patterns))))
49-
signalPassFailure();
50-
}
51-
};
5232
} // namespace
5333

5434
FailureOr<scf::ForOp> mlir::scf::upliftWhileToForLoop(RewriterBase &rewriter,

mlir/test/lib/Dialect/SCF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_mlir_library(MLIRSCFTestPasses
44
TestLoopUnrolling.cpp
55
TestSCFUtils.cpp
66
TestSCFWrapInZeroTripCheck.cpp
7+
TestUpliftWhileToFor.cpp
78
TestWhileOpBuilder.cpp
89

910
EXCLUDE_FROM_LIBMLIR
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===- TestUpliftWhileToFor.cpp - while to for loop uplifting test pass ---===//
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+
// Pass to test transforms SCF.WhileOp's into SCF.ForOp's.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Dialect/SCF/Transforms/Patterns.h"
14+
#include "mlir/IR/PatternMatch.h"
15+
#include "mlir/Pass/Pass.h"
16+
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
17+
18+
using namespace mlir;
19+
20+
namespace {
21+
22+
struct TestSCFUpliftWhileToFor
23+
: public PassWrapper<TestSCFUpliftWhileToFor, OperationPass<void>> {
24+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFUpliftWhileToFor)
25+
26+
StringRef getArgument() const final { return "test-scf-uplift-while-to-for"; }
27+
28+
StringRef getDescription() const final {
29+
return "test scf while to for uplifting";
30+
}
31+
32+
void runOnOperation() override {
33+
Operation *op = getOperation();
34+
MLIRContext *ctx = op->getContext();
35+
RewritePatternSet patterns(ctx);
36+
scf::populateUpliftWhileToForPatterns(patterns);
37+
if (failed(applyPatternsAndFoldGreedily(op, std::move(patterns))))
38+
signalPassFailure();
39+
}
40+
};
41+
42+
} // namespace
43+
44+
namespace mlir {
45+
namespace test {
46+
void registerTestSCFUpliftWhileToFor() {
47+
PassRegistration<TestSCFUpliftWhileToFor>();
48+
}
49+
} // namespace test
50+
} // namespace mlir

mlir/tools/mlir-opt/mlir-opt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void registerTestOneToNTypeConversionPass();
130130
void registerTestOpaqueLoc();
131131
void registerTestPadFusion();
132132
void registerTestRecursiveTypesPass();
133+
void registerTestSCFUpliftWhileToFor();
133134
void registerTestSCFUtilsPass();
134135
void registerTestSCFWhileOpBuilderPass();
135136
void registerTestSCFWrapInZeroTripCheckPasses();
@@ -258,6 +259,7 @@ void registerTestPasses() {
258259
mlir::test::registerTestOpaqueLoc();
259260
mlir::test::registerTestPadFusion();
260261
mlir::test::registerTestRecursiveTypesPass();
262+
mlir::test::registerTestSCFUpliftWhileToFor();
261263
mlir::test::registerTestSCFUtilsPass();
262264
mlir::test::registerTestSCFWhileOpBuilderPass();
263265
mlir::test::registerTestSCFWrapInZeroTripCheckPasses();

0 commit comments

Comments
 (0)