aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/SCF/TestUpliftWhileToFor.cpp
blob: cf123fe280242ac7d7681871e54b15e7bc9ec643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===- TestUpliftWhileToFor.cpp - while to for loop uplifting test pass ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Pass to test transforms SCF.WhileOp's into SCF.ForOp's.
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/SCF/Transforms/Patterns.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

using namespace mlir;

namespace {

struct TestSCFUpliftWhileToFor
    : public PassWrapper<TestSCFUpliftWhileToFor, OperationPass<void>> {
  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFUpliftWhileToFor)

  StringRef getArgument() const final { return "test-scf-uplift-while-to-for"; }

  StringRef getDescription() const final {
    return "test scf while to for uplifting";
  }

  void runOnOperation() override {
    Operation *op = getOperation();
    MLIRContext *ctx = op->getContext();
    RewritePatternSet patterns(ctx);
    scf::populateUpliftWhileToForPatterns(patterns);
    if (failed(applyPatternsGreedily(op, std::move(patterns))))
      signalPassFailure();
  }
};

} // namespace

namespace mlir {
namespace test {
void registerTestSCFUpliftWhileToFor() {
  PassRegistration<TestSCFUpliftWhileToFor>();
}
} // namespace test
} // namespace mlir