|
| 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 |
0 commit comments