1b153c05cSIvan Butygin //===- TestUpliftWhileToFor.cpp - while to for loop uplifting test pass ---===// 2b153c05cSIvan Butygin // 3b153c05cSIvan Butygin // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b153c05cSIvan Butygin // See https://llvm.org/LICENSE.txt for license information. 5b153c05cSIvan Butygin // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b153c05cSIvan Butygin // 7b153c05cSIvan Butygin //===----------------------------------------------------------------------===// 8b153c05cSIvan Butygin // 9b153c05cSIvan Butygin // Pass to test transforms SCF.WhileOp's into SCF.ForOp's. 10b153c05cSIvan Butygin // 11b153c05cSIvan Butygin //===----------------------------------------------------------------------===// 12b153c05cSIvan Butygin 13b153c05cSIvan Butygin #include "mlir/Dialect/SCF/Transforms/Patterns.h" 14b153c05cSIvan Butygin #include "mlir/IR/PatternMatch.h" 15b153c05cSIvan Butygin #include "mlir/Pass/Pass.h" 16b153c05cSIvan Butygin #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 17b153c05cSIvan Butygin 18b153c05cSIvan Butygin using namespace mlir; 19b153c05cSIvan Butygin 20b153c05cSIvan Butygin namespace { 21b153c05cSIvan Butygin 22b153c05cSIvan Butygin struct TestSCFUpliftWhileToFor 23b153c05cSIvan Butygin : public PassWrapper<TestSCFUpliftWhileToFor, OperationPass<void>> { 24b153c05cSIvan Butygin MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFUpliftWhileToFor) 25b153c05cSIvan Butygin 26b153c05cSIvan Butygin StringRef getArgument() const final { return "test-scf-uplift-while-to-for"; } 27b153c05cSIvan Butygin 28b153c05cSIvan Butygin StringRef getDescription() const final { 29b153c05cSIvan Butygin return "test scf while to for uplifting"; 30b153c05cSIvan Butygin } 31b153c05cSIvan Butygin 32b153c05cSIvan Butygin void runOnOperation() override { 33b153c05cSIvan Butygin Operation *op = getOperation(); 34b153c05cSIvan Butygin MLIRContext *ctx = op->getContext(); 35b153c05cSIvan Butygin RewritePatternSet patterns(ctx); 36b153c05cSIvan Butygin scf::populateUpliftWhileToForPatterns(patterns); 37*09dfc571SJacques Pienaar if (failed(applyPatternsGreedily(op, std::move(patterns)))) 38b153c05cSIvan Butygin signalPassFailure(); 39b153c05cSIvan Butygin } 40b153c05cSIvan Butygin }; 41b153c05cSIvan Butygin 42b153c05cSIvan Butygin } // namespace 43b153c05cSIvan Butygin 44b153c05cSIvan Butygin namespace mlir { 45b153c05cSIvan Butygin namespace test { 46b153c05cSIvan Butygin void registerTestSCFUpliftWhileToFor() { 47b153c05cSIvan Butygin PassRegistration<TestSCFUpliftWhileToFor>(); 48b153c05cSIvan Butygin } 49b153c05cSIvan Butygin } // namespace test 50b153c05cSIvan Butygin } // namespace mlir 51