[Mlir-commits] [mlir] 4b728ff - [mlir] optional verbose debug messages for transform application

Alex Zinenko llvmlistbot at llvm.org
Tue Sep 13 09:01:30 PDT 2022


Author: Alex Zinenko
Date: 2022-09-13T18:01:19+02:00
New Revision: 4b728ff076343a7d90a89f303857e88c1827fa09

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

LOG: [mlir] optional verbose debug messages for transform application

Introduce the additional "transform-dialect-print-top-level-after-all" debug
category that allows the user to print the paylaod IR after each transformation
performed by the transform dialect. This is useful for understanding and
debugging the effects of individual transformations in complex transformations
scripts, including in downstreams, without having to modify the transformation
script itself.

Reviewed By: mravishankar

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp b/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp
index f1dd41a4a761..b78b8ab621e5 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Support/Debug.h"
 
 #define DEBUG_TYPE "transform-dialect"
+#define DEBUG_PRINT_AFTER_ALL "transform-dialect-print-top-level-after-all"
 #define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "] ")
 
 using namespace mlir;
@@ -194,6 +195,13 @@ LogicalResult transform::TransformState::checkAndRecordHandleInvalidation(
 DiagnosedSilenceableFailure
 transform::TransformState::applyTransform(TransformOpInterface transform) {
   LLVM_DEBUG(DBGS() << "applying: " << transform << "\n");
+  auto printOnFailureRAII = llvm::make_scope_exit([this] {
+    DEBUG_WITH_TYPE(DEBUG_PRINT_AFTER_ALL, {
+      DBGS() << "Top-level payload:\n";
+      getTopLevel()->print(llvm::dbgs(),
+                           mlir::OpPrintingFlags().printGenericOpForm());
+    });
+  });
   if (options.getExpensiveChecksEnabled()) {
     if (failed(checkAndRecordHandleInvalidation(transform)))
       return DiagnosedSilenceableFailure::definiteFailure();
@@ -247,6 +255,11 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
       return DiagnosedSilenceableFailure::definiteFailure();
   }
 
+  printOnFailureRAII.release();
+  DEBUG_WITH_TYPE(DEBUG_PRINT_AFTER_ALL, {
+    DBGS() << "Top-level payload:\n";
+    getTopLevel()->print(llvm::dbgs());
+  });
   return DiagnosedSilenceableFailure::success();
 }
 


        


More information about the Mlir-commits mailing list