[Mlir-commits] [mlir] aa051a0 - [mlir][Transforms][NFC] GreedyPatternRewriteDriver: Reformat debug logic

Matthias Springer llvmlistbot at llvm.org
Wed May 24 07:05:52 PDT 2023


Author: Matthias Springer
Date: 2023-05-24T16:05:43+02:00
New Revision: aa051a0950c31bb11072d8c4f09ff473f0e6363d

URL: https://github.com/llvm/llvm-project/commit/aa051a0950c31bb11072d8c4f09ff473f0e6363d
DIFF: https://github.com/llvm/llvm-project/commit/aa051a0950c31bb11072d8c4f09ff473f0e6363d.diff

LOG: [mlir][Transforms][NFC] GreedyPatternRewriteDriver: Reformat debug logic

Do not duplicate code that is performing actual work, put debug code around it.

Differential Revision: https://reviews.llvm.org/D151207

Added: 
    

Modified: 
    mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index 3bdd99e5bab53..f6e7fa18a7789 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -207,39 +207,40 @@ bool GreedyPatternRewriteDriver::processWorklist() {
     // notified of any necessary changes, so there is nothing else to do
     // here.
 #ifndef NDEBUG
-      auto canApply = [&](const Pattern &pattern) {
-        LLVM_DEBUG({
-          logger.getOStream() << "\n";
-          logger.startLine() << "* Pattern " << pattern.getDebugName() << " : '"
-                             << op->getName() << " -> (";
-          llvm::interleaveComma(pattern.getGeneratedOps(), logger.getOStream());
-          logger.getOStream() << ")' {\n";
-          logger.indent();
-        });
-        return true;
-      };
-      auto onFailure = [&](const Pattern &pattern) {
-        LLVM_DEBUG(logResult("failure", "pattern failed to match"));
-      };
-      auto onSuccess = [&](const Pattern &pattern) {
-        LLVM_DEBUG(logResult("success", "pattern applied successfully"));
-        return success();
-      };
-
-      LogicalResult matchResult =
-          matcher.matchAndRewrite(op, *this, canApply, onFailure, onSuccess);
-      if (succeeded(matchResult))
-        LLVM_DEBUG(logResultWithLine("success", "pattern matched"));
-      else
-        LLVM_DEBUG(logResultWithLine("failure", "pattern failed to match"));
+    auto canApply = [&](const Pattern &pattern) {
+      LLVM_DEBUG({
+        logger.getOStream() << "\n";
+        logger.startLine() << "* Pattern " << pattern.getDebugName() << " : '"
+                           << op->getName() << " -> (";
+        llvm::interleaveComma(pattern.getGeneratedOps(), logger.getOStream());
+        logger.getOStream() << ")' {\n";
+        logger.indent();
+      });
+      return true;
+    };
+    auto onFailure = [&](const Pattern &pattern) {
+      LLVM_DEBUG(logResult("failure", "pattern failed to match"));
+    };
+    auto onSuccess = [&](const Pattern &pattern) {
+      LLVM_DEBUG(logResult("success", "pattern applied successfully"));
+      return success();
+    };
 #else
-      LogicalResult matchResult = matcher.matchAndRewrite(op, *this);
+    function_ref<bool(const Pattern &)> canApply = {};
+    function_ref<void(const Pattern &)> onFailure = {};
+    function_ref<LogicalResult(const Pattern &)> onSuccess = {};
 #endif
 
-      if (succeeded(matchResult)) {
-        changed = true;
-        ++numRewrites;
-      }
+    LogicalResult matchResult =
+        matcher.matchAndRewrite(op, *this, canApply, onFailure, onSuccess);
+
+    if (succeeded(matchResult)) {
+      LLVM_DEBUG(logResultWithLine("success", "pattern matched"));
+      changed = true;
+      ++numRewrites;
+    } else {
+      LLVM_DEBUG(logResultWithLine("failure", "pattern failed to match"));
+    }
   }
 
   return changed;


        


More information about the Mlir-commits mailing list