[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 7 20:12:11 PST 2024


================
@@ -562,30 +562,39 @@ bool GreedyPatternRewriteDriver::processWorklist() {
     // Try to match one of the patterns. The rewriter is automatically
     // notified of any necessary changes, so there is nothing else to do
     // here.
+    std::function<bool(const Pattern &)> canApply = nullptr;
+    std::function<void(const Pattern &)> onFailure = nullptr;
+    std::function<LogicalResult(const Pattern &)> onSuccess = nullptr;
+    bool debugBuild = false;
 #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();
-    };
-#else
-    function_ref<bool(const Pattern &)> canApply = {};
-    function_ref<void(const Pattern &)> onFailure = {};
-    function_ref<LogicalResult(const Pattern &)> onSuccess = {};
-#endif
+    debugBuild = true;
----------------
joker-eph wrote:

Why changing the structure of the code with this variable?

https://github.com/llvm/llvm-project/pull/84131


More information about the llvm-branch-commits mailing list