1 //===- TestUpliftWhileToFor.cpp - while to for loop uplifting test pass ---===//
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
7 //===----------------------------------------------------------------------===//
9 // Pass to test transforms SCF.WhileOp's into SCF.ForOp's.
11 //===----------------------------------------------------------------------===//
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"
22 struct TestSCFUpliftWhileToFor
23 : public PassWrapper
<TestSCFUpliftWhileToFor
, OperationPass
<void>> {
24 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFUpliftWhileToFor
)
26 StringRef
getArgument() const final
{ return "test-scf-uplift-while-to-for"; }
28 StringRef
getDescription() const final
{
29 return "test scf while to for uplifting";
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
))))
46 void registerTestSCFUpliftWhileToFor() {
47 PassRegistration
<TestSCFUpliftWhileToFor
>();