Files
clang-p2996/mlir/test/lib/Dialect/SCF/TestUpliftWhileToFor.cpp
Ivan Butygin b153c05cba [mlir][scf] Uplift scf.while to scf.for (#76108)
Add uplifting from `scf.while` to `scf.for`.

This uplifting expects a very specific ops pattern:
* `before` block consisting of single `arith.cmp` op
* `after` block containing `arith.addi`

We also have a set of patterns to cleanup `scf.while` loops to get them
close to the desired form, they will be added in separate PRs.

This is part of upstreaming `numba-mlir` scf uplifting pipeline: `cf ->
scf.while -> scf.for -> scf.parallel`

Original code:
https://github.com/numba/numba-mlir/blob/main/mlir/lib/Transforms/PromoteToParallel.cpp
2024-04-15 22:16:59 +03:00

51 lines
1.5 KiB
C++

//===- 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(applyPatternsAndFoldGreedily(op, std::move(patterns))))
signalPassFailure();
}
};
} // namespace
namespace mlir {
namespace test {
void registerTestSCFUpliftWhileToFor() {
PassRegistration<TestSCFUpliftWhileToFor>();
}
} // namespace test
} // namespace mlir