xref: /llvm-project/mlir/test/lib/Dialect/SCF/TestUpliftWhileToFor.cpp (revision 09dfc5713d7e2342bea4c8447d1ed76c85eb8225)
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(applyPatternsGreedily(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
51