17
17
#include " llvm/Support/ErrorHandling.h"
18
18
19
19
#define DEBUG_TYPE " transform-dialect"
20
+ #define DEBUG_TYPE_FULL " transform-dialect-full"
20
21
#define DEBUG_PRINT_AFTER_ALL " transform-dialect-print-top-level-after-all"
21
22
#define DBGS () (llvm::dbgs() << " [" DEBUG_TYPE " ] " )
23
+ #define LDBG (X ) LLVM_DEBUG(DBGS() << (X))
22
24
23
25
using namespace mlir ;
24
26
@@ -396,7 +398,17 @@ void transform::TransformState::recordOpHandleInvalidationOne(
396
398
if (invalidatedHandles.count (otherHandle))
397
399
return ;
398
400
401
+ LDBG (" --recordOpHandleInvalidationOne\n " );
402
+ LLVM_DEBUG (llvm::interleaveComma (potentialAncestors,
403
+ DBGS () << " --ancestors: " ,
404
+ [](Operation *op) { llvm::dbgs () << *op; });
405
+ llvm::dbgs () << " \n " );
399
406
for (Operation *ancestor : potentialAncestors) {
407
+ LLVM_DEBUG (DBGS () << " ----handle one ancestor: " << *ancestor << " \n " );
408
+ LLVM_DEBUG (DBGS () << " ----of payload with name: "
409
+ << payloadOp->getName ().getIdentifier () << " \n " );
410
+ DEBUG_WITH_TYPE (DEBUG_TYPE_FULL,
411
+ { (DBGS () << " ----of payload: " << *payloadOp << " \n " ); });
400
412
if (!ancestor->isAncestor (payloadOp))
401
413
continue ;
402
414
@@ -562,18 +574,23 @@ void transform::TransformState::recordValueHandleInvalidation(
562
574
563
575
LogicalResult transform::TransformState::checkAndRecordHandleInvalidation (
564
576
TransformOpInterface transform) {
577
+ LDBG (" --Start checkAndRecordHandleInvalidation\n " );
565
578
auto memoryEffectsIface =
566
579
cast<MemoryEffectOpInterface>(transform.getOperation ());
567
580
SmallVector<MemoryEffects::EffectInstance> effects;
568
581
memoryEffectsIface.getEffectsOnResource (
569
582
transform::TransformMappingResource::get (), effects);
570
583
571
584
for (OpOperand &target : transform->getOpOperands ()) {
585
+ LLVM_DEBUG (DBGS () << " ----iterate on handle: " << target.get () << " \n " );
572
586
// If the operand uses an invalidated handle, report it.
573
587
auto it = invalidatedHandles.find (target.get ());
574
588
if (!transform.allowsRepeatedHandleOperands () &&
575
- it != invalidatedHandles.end ())
589
+ it != invalidatedHandles.end ()) {
590
+ LLVM_DEBUG (
591
+ DBGS () << " --End checkAndRecordHandleInvalidation -> FAILURE\n " );
576
592
return it->getSecond ()(transform->getLoc ()), failure ();
593
+ }
577
594
578
595
// Invalidate handles pointing to the operations nested in the operation
579
596
// associated with the handle consumed by this operation.
@@ -582,17 +599,25 @@ LogicalResult transform::TransformState::checkAndRecordHandleInvalidation(
582
599
effect.getValue () == target.get ();
583
600
};
584
601
if (llvm::any_of (effects, consumesTarget)) {
602
+ LLVM_DEBUG (DBGS () << " ----found consume effect -> SKIP\n " );
585
603
if (target.get ().getType ().isa <TransformHandleTypeInterface>()) {
604
+ LDBG (" ----recordOpHandleInvalidation\n " );
586
605
ArrayRef<Operation *> payloadOps = getPayloadOps (target.get ());
587
606
recordOpHandleInvalidation (target, payloadOps);
588
607
} else if (target.get ()
589
608
.getType ()
590
609
.isa <TransformValueHandleTypeInterface>()) {
610
+ LDBG (" ----recordValueHandleInvalidation\n " );
591
611
recordValueHandleInvalidation (target);
612
+ } else {
613
+ LDBG (" ----not a TransformHandle -> SKIP AND DROP ON THE FLOOR\n " );
592
614
}
615
+ } else {
616
+ LLVM_DEBUG (DBGS () << " ----no consume effect -> SKIP\n " );
593
617
}
594
618
}
595
619
620
+ LDBG (" --End checkAndRecordHandleInvalidation -> SUCCESS\n " );
596
621
return success ();
597
622
}
598
623
@@ -621,7 +646,7 @@ checkRepeatedConsumptionInOperand(ArrayRef<T> payload,
621
646
622
647
DiagnosedSilenceableFailure
623
648
transform::TransformState::applyTransform (TransformOpInterface transform) {
624
- LLVM_DEBUG (DBGS () << " applying: " << transform << " \n " );
649
+ LLVM_DEBUG (DBGS () << " \n " ; DBGS () << " applying: " << transform << " \n " );
625
650
auto printOnFailureRAII = llvm::make_scope_exit ([this ] {
626
651
(void )this ;
627
652
DEBUG_WITH_TYPE (DEBUG_PRINT_AFTER_ALL, {
@@ -631,28 +656,42 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
631
656
});
632
657
});
633
658
if (options.getExpensiveChecksEnabled ()) {
659
+ LDBG (" ExpensiveChecksEnabled\n " );
634
660
if (failed (checkAndRecordHandleInvalidation (transform)))
635
661
return DiagnosedSilenceableFailure::definiteFailure ();
636
662
637
663
for (OpOperand &operand : transform->getOpOperands ()) {
638
- if (!isHandleConsumed (operand.get (), transform))
664
+ LLVM_DEBUG (DBGS () << " iterate on handle: " << operand.get () << " \n " );
665
+ if (!isHandleConsumed (operand.get (), transform)) {
666
+ LDBG (" --handle not consumed -> SKIP\n " );
639
667
continue ;
668
+ }
669
+ LDBG (" --handle is consumed\n " );
640
670
641
671
Type operandType = operand.get ().getType ();
642
672
if (operandType.isa <TransformHandleTypeInterface>()) {
673
+ LLVM_DEBUG (
674
+ DBGS () << " --checkRepeatedConsumptionInOperand for Operation*\n " );
643
675
DiagnosedSilenceableFailure check =
644
676
checkRepeatedConsumptionInOperand<Operation *>(
645
677
getPayloadOps (operand.get ()), transform,
646
678
operand.getOperandNumber ());
647
- if (!check.succeeded ())
679
+ if (!check.succeeded ()) {
680
+ LDBG (" ----FAILED\n " );
648
681
return check;
682
+ }
649
683
} else if (operandType.isa <TransformValueHandleTypeInterface>()) {
684
+ LDBG (" --checkRepeatedConsumptionInOperand For Value\n " );
650
685
DiagnosedSilenceableFailure check =
651
686
checkRepeatedConsumptionInOperand<Value>(
652
687
getPayloadValues (operand.get ()), transform,
653
688
operand.getOperandNumber ());
654
- if (!check.succeeded ())
689
+ if (!check.succeeded ()) {
690
+ LDBG (" ----FAILED\n " );
655
691
return check;
692
+ }
693
+ } else {
694
+ LDBG (" --not a TransformHandle -> SKIP AND DROP ON THE FLOOR\n " );
656
695
}
657
696
}
658
697
}
0 commit comments