@@ -136,6 +136,21 @@ struct DebugFingerPrints : public RewriterBase::ForwardingListener {
136
136
};
137
137
#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
138
138
139
+ #ifndef NDEBUG
140
+ static Operation *getDumpRootOp (Operation *op) {
141
+ // Dump the parent op so that materialized constants are visible. If the op
142
+ // is a top-level op, dump it directly.
143
+ if (Operation *parentOp = op->getParentOp ())
144
+ return parentOp;
145
+ return op;
146
+ }
147
+ static void logSuccessfulFolding (Operation *op) {
148
+ llvm::dbgs () << " // *** IR Dump After Successful Folding ***\n " ;
149
+ op->dump ();
150
+ llvm::dbgs () << " \n\n " ;
151
+ }
152
+ #endif // NDEBUG
153
+
139
154
// ===----------------------------------------------------------------------===//
140
155
// Worklist
141
156
// ===----------------------------------------------------------------------===//
@@ -434,10 +449,14 @@ bool GreedyPatternRewriteDriver::processWorklist() {
434
449
SmallVector<OpFoldResult> foldResults;
435
450
if (succeeded (op->fold (foldResults))) {
436
451
LLVM_DEBUG (logResultWithLine (" success" , " operation was folded" ));
452
+ #ifndef NDEBUG
453
+ Operation *dumpRootOp = getDumpRootOp (op);
454
+ #endif // NDEBUG
437
455
if (foldResults.empty ()) {
438
456
// Op was modified in-place.
439
457
notifyOperationModified (op);
440
458
changed = true ;
459
+ LLVM_DEBUG (logSuccessfulFolding (dumpRootOp));
441
460
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
442
461
if (config.scope && failed (verify (config.scope ->getParentOp ())))
443
462
llvm::report_fatal_error (" IR failed to verify after folding" );
@@ -492,6 +511,7 @@ bool GreedyPatternRewriteDriver::processWorklist() {
492
511
if (materializationSucceeded) {
493
512
replaceOp (op, replacements);
494
513
changed = true ;
514
+ LLVM_DEBUG (logSuccessfulFolding (dumpRootOp));
495
515
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
496
516
if (config.scope && failed (verify (config.scope ->getParentOp ())))
497
517
llvm::report_fatal_error (" IR failed to verify after folding" );
0 commit comments