[Mlir-commits] [mlir] [mlir] Add transformation to wrap scf::while in zero-trip-check (PR #81050)
Diego Caballero
llvmlistbot at llvm.org
Wed Feb 7 23:16:10 PST 2024
================
@@ -0,0 +1,58 @@
+//===- TestWrapInZeroTripCheck.cpp -- Passes to test SCF zero-trip-check --===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the passes to test wrap-in-zero-trip-check transforms on
+// SCF loop ops.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/SCF/IR/SCF.h"
+#include "mlir/Dialect/SCF/Transforms/Transforms.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Pass/Pass.h"
+
+using namespace mlir;
+
+namespace {
+
+struct TestWrapWhileLoopInZeroTripCheck
+ : public PassWrapper<TestWrapWhileLoopInZeroTripCheck,
+ OperationPass<func::FuncOp>> {
+ MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestWrapWhileLoopInZeroTripCheck)
+
+ StringRef getArgument() const final {
+ return "test-wrap-scf-while-loop-in-zero-trip-check";
+ }
+ StringRef getDescription() const final {
+ return "test scf::wrapWhileLoopInZeroTripCheck";
+ }
+
+ void runOnOperation() override {
+ func::FuncOp func = getOperation();
+ MLIRContext *context = &getContext();
+ IRRewriter rewriter(context);
+ func.walk([&](scf::WhileOp op) {
+ auto result = scf::wrapWhileLoopInZeroTripCheck(op, rewriter);
+ if (failed(result)) {
+ // Ignore not implemented failure in tests. The expected output should
+ // catch problems (e.g. transformation doesn't happen).
+ }
----------------
dcaballe wrote:
You could then remove the `if`? Perhaps you have to add a `(void) result;` to silence warnings?
https://github.com/llvm/llvm-project/pull/81050
More information about the Mlir-commits
mailing list