Skip to content

Commit bd919fb

Browse files
author
Jerry Wu
committed
Add test pass
1 parent ab65656 commit bd919fb

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

mlir/test/lib/Interfaces/LoopLikeInterface/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_mlir_library(MLIRLoopLikeInterfaceTestPasses
22
TestBlockInLoop.cpp
3+
TestLoopZeroTripCheck.cpp
34

45
EXCLUDE_FROM_LIBMLIR
56

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===- TestLoopZeroTripCheck.cpp.cpp -- Pass to test replaceWithZeroTripC--===//
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+
// This file implements the passes to test replaceWithZeroTripCheck of loop ops.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Dialect/Func/IR/FuncOps.h"
14+
#include "mlir/IR/PatternMatch.h"
15+
#include "mlir/Interfaces/LoopLikeInterface.h"
16+
#include "mlir/Pass/Pass.h"
17+
18+
using namespace mlir;
19+
20+
namespace {
21+
22+
struct TestLoopZeroTripCheck
23+
: public PassWrapper<TestLoopZeroTripCheck, OperationPass<func::FuncOp>> {
24+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLoopZeroTripCheck)
25+
26+
StringRef getArgument() const final { return "test-loop-zero-trip-check"; }
27+
StringRef getDescription() const final {
28+
return "test replaceWithZeroTripCheck of loop ops";
29+
}
30+
31+
void runOnOperation() override {
32+
func::FuncOp func = getOperation();
33+
MLIRContext *context = &getContext();
34+
IRRewriter rewriter(context);
35+
func.walk([&](LoopLikeOpInterface op) {
36+
auto result = op.replaceWithZeroTripCheck(rewriter);
37+
if (failed(result)) {
38+
// Ignore failures (e.g. not implemented) in tests.
39+
}
40+
});
41+
}
42+
};
43+
44+
} // namespace
45+
46+
namespace mlir {
47+
namespace test {
48+
void registerTestLoopZeroTripCheckPass() {
49+
PassRegistration<TestLoopZeroTripCheck>();
50+
}
51+
} // namespace test
52+
} // namespace mlir

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void registerTestLoopFusion();
110110
void registerTestCFGLoopInfoPass();
111111
void registerTestLoopMappingPass();
112112
void registerTestLoopUnrollingPass();
113+
void registerTestLoopZeroTripCheckPass();
113114
void registerTestLowerToLLVM();
114115
void registerTestLowerToNVVM();
115116
void registerTestMakeIsolatedFromAbovePass();
@@ -234,6 +235,7 @@ void registerTestPasses() {
234235
mlir::test::registerTestCFGLoopInfoPass();
235236
mlir::test::registerTestLoopMappingPass();
236237
mlir::test::registerTestLoopUnrollingPass();
238+
mlir::test::registerTestLoopZeroTripCheckPass();
237239
mlir::test::registerTestLowerToLLVM();
238240
mlir::test::registerTestMakeIsolatedFromAbovePass();
239241
mlir::test::registerTestMatchReductionPass();

0 commit comments

Comments
 (0)