[Mlir-commits] [mlir] 6a494e1 - [MLIR] Add debug support for ignored patterns

Frederik Gossen llvmlistbot at llvm.org
Wed Sep 9 00:18:51 PDT 2020


Author: Frederik Gossen
Date: 2020-09-09T07:18:30Z
New Revision: 6a494e117cd99fc5b4c728d9f5a78ae817f93434

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

LOG: [MLIR] Add debug support for ignored patterns

The rewrite engine's cost model may determine some patterns to be irrelevant
ahead of their application. These patterns were silently ignored previously and
now cause a message in `--debug` mode.

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

Added: 
    

Modified: 
    mlir/lib/IR/PatternMatch.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp
index a26bc63ed89d..d1da8d1d8f26 100644
--- a/mlir/lib/IR/PatternMatch.cpp
+++ b/mlir/lib/IR/PatternMatch.cpp
@@ -10,9 +10,12 @@
 #include "mlir/IR/BlockAndValueMapping.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/Value.h"
+#include "llvm/Support/Debug.h"
 
 using namespace mlir;
 
+#define DEBUG_TYPE "pattern-match"
+
 PatternBenefit::PatternBenefit(unsigned benefit) : representation(benefit) {
   assert(representation == benefit && benefit != ImpossibleToMatchSentinel &&
          "This pattern match benefit is too large to represent");
@@ -207,8 +210,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
   anyOpPatterns.clear();
   for (const auto &pat : owningPatternList) {
     // If the pattern is always impossible to match, just ignore it.
-    if (pat->getBenefit().isImpossibleToMatch())
+    if (pat->getBenefit().isImpossibleToMatch()) {
+      LLVM_DEBUG({
+        llvm::dbgs()
+            << "Ignoring pattern '" << pat->getRootKind()
+            << "' because it is impossible to match (by pattern benefit)\n";
+      });
       continue;
+    }
     if (Optional<OperationName> opName = pat->getRootKind())
       patterns[*opName].push_back(pat.get());
     else
@@ -223,8 +232,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
   auto processPatternList = [&](SmallVectorImpl<RewritePattern *> &list) {
     // Special case for one pattern in the list, which is the most common case.
     if (list.size() == 1) {
-      if (model(*list.front()).isImpossibleToMatch())
+      if (model(*list.front()).isImpossibleToMatch()) {
+        LLVM_DEBUG({
+          llvm::dbgs() << "Ignoring pattern '" << list.front()->getRootKind()
+                       << "' because it is impossible to match or cannot lead "
+                          "to legal IR (by cost model)\n";
+        });
         list.clear();
+      }
       return;
     }
 
@@ -236,8 +251,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
     // Sort patterns with highest benefit first, and remove those that are
     // impossible to match.
     std::stable_sort(list.begin(), list.end(), cmp);
-    while (!list.empty() && benefits[list.back()].isImpossibleToMatch())
+    while (!list.empty() && benefits[list.back()].isImpossibleToMatch()) {
+      LLVM_DEBUG({
+        llvm::dbgs() << "Ignoring pattern '" << list.back()->getRootKind()
+                     << "' because it is impossible to match or cannot lead to "
+                        "legal IR (by cost model)\n";
+      });
       list.pop_back();
+    }
   };
   for (auto &it : patterns)
     processPatternList(it.second);


        


More information about the Mlir-commits mailing list