5656#include " mlir/Interfaces/SubsetOpInterface.h"
5757#include " llvm/ADT/DenseSet.h"
5858#include " llvm/ADT/SetVector.h"
59+ #include " llvm/Support/DebugLog.h"
5960
6061MLIR_DEFINE_EXPLICIT_TYPE_ID (mlir::bufferization::OneShotAnalysisState)
6162
@@ -616,13 +617,10 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
616617 if (getParallelRegion (def.getParentRegion (), options) !=
617618 getParallelRegion (uConflictingWrite->getOwner ()->getParentRegion (),
618619 options)) {
619- LLVM_DEBUG (
620- llvm::dbgs ()
621- << " \n - bufferizes out-of-place due to parallel region:\n " );
622- LLVM_DEBUG (llvm::dbgs ()
623- << " unConflictingWrite = operand "
624- << uConflictingWrite->getOperandNumber () << " of "
625- << *uConflictingWrite->getOwner () << " \n " );
620+ LDBG () << " \n - bufferizes out-of-place due to parallel region:\n "
621+ << " unConflictingWrite = operand "
622+ << uConflictingWrite->getOperandNumber () << " of "
623+ << *uConflictingWrite->getOwner ();
626624 return true ;
627625 }
628626 }
@@ -631,9 +629,9 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
631629
632630 for (OpOperand *uRead : usesRead) {
633631 Operation *readingOp = uRead->getOwner ();
634- LLVM_DEBUG ( llvm::dbgs ( ) << " \n - check conflict:\n " );
635- LLVM_DEBUG ( llvm::dbgs () << " uRead = operand " << uRead->getOperandNumber ()
636- << " of " << *readingOp << " \n " ) ;
632+ LDBG ( ) << " \n - check conflict:\n "
633+ << " uRead = operand " << uRead->getOperandNumber () << " of "
634+ << *readingOp;
637635
638636 // Find the definition of uRead by following the SSA use-def chain.
639637 // E.g.:
@@ -648,23 +646,22 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
648646 const SetVector<Value> &definitions = state.findDefinitionsCached (uRead);
649647 if (definitions.empty ()) {
650648 // Fast path: No conflict if there are no definitions.
651- LLVM_DEBUG (llvm::dbgs ()
652- << " no conflict: read value has no definitions\n " );
649+ LDBG () << " no conflict: read value has no definitions" ;
653650 continue ;
654651 }
655652
656653 // Look for conflicting memory writes. Potential conflicts are writes to an
657654 // alias that have been decided to bufferize inplace.
658655 for (OpOperand *uConflictingWrite : usesWrite) {
659- LLVM_DEBUG ( llvm::dbgs () << " unConflictingWrite = operand "
660- << uConflictingWrite->getOperandNumber () << " of "
661- << *uConflictingWrite->getOwner () << " \n " );
656+ LDBG () << " unConflictingWrite = operand "
657+ << uConflictingWrite->getOperandNumber () << " of "
658+ << *uConflictingWrite->getOwner ();
662659
663660 // Check if op dominance can be used to rule out read-after-write
664661 // conflicts.
665662 bool useDominance =
666663 canUseOpDominance (uRead, uConflictingWrite, definitions, state);
667- LLVM_DEBUG ( llvm::dbgs ( ) << " \n - useDominance = " << useDominance << " \n " ) ;
664+ LDBG ( ) << " \n - useDominance = " << useDominance;
668665
669666 // Throughout this loop, check for multiple requirements that have to be
670667 // met for uConflictingWrite to be an actual conflict.
@@ -680,8 +677,7 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
680677 // inside a loop), there may be no meaningful `happensBefore`
681678 // relationship.
682679 if (happensBefore (readingOp, conflictingWritingOp, domInfo)) {
683- LLVM_DEBUG (llvm::dbgs ()
684- << " no conflict: read happens before write\n " );
680+ LDBG () << " no conflict: read happens before write" ;
685681 continue ;
686682 }
687683
@@ -693,8 +689,7 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
693689 // Note: If the op is executed multiple times (e.g., because it is
694690 // inside a loop), it may be conflicting with itself.
695691 if (uConflictingWrite == uRead) {
696- LLVM_DEBUG (llvm::dbgs ()
697- << " no conflict: read and write are same use\n " );
692+ LDBG () << " no conflict: read and write are same use" ;
698693 continue ;
699694 }
700695
@@ -705,8 +700,8 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
705700 // multiple times.
706701 if (state.insideMutuallyExclusiveRegions (readingOp,
707702 conflictingWritingOp)) {
708- LLVM_DEBUG ( llvm::dbgs () << " no conflict: read and write are in "
709- " mutually exclusive regions\n " ) ;
703+ LDBG () << " no conflict: read and write are in "
704+ " mutually exclusive regions" ;
710705 continue ;
711706 }
712707
@@ -721,9 +716,7 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
721716 state, uRead, uConflictingWrite->get ()) ||
722717 hasEquivalentValueInReverseUseDefChain (
723718 state, uConflictingWrite, uRead->get ())) {
724- LLVM_DEBUG (
725- llvm::dbgs ()
726- << " no conflict: op bufferizes to element-wise access\n " );
719+ LDBG () << " no conflict: op bufferizes to element-wise access" ;
727720 continue ;
728721 }
729722 }
@@ -733,15 +726,14 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
733726
734727 // No conflict if the operands are non-conflicting subsets.
735728 if (areNonConflictingSubsets (uRead, uConflictingWrite, state)) {
736- LLVM_DEBUG ( llvm::dbgs ( ) << " no conflict: non-conflicting subsets\n " ) ;
729+ LDBG ( ) << " no conflict: non-conflicting subsets" ;
737730 continue ;
738731 }
739732
740733 // No conflict if the op interface says so.
741734 if (auto bufferizableOp = options.dynCastBufferizableOp (readingOp)) {
742735 if (bufferizableOp.isNotConflicting (uRead, uConflictingWrite, state)) {
743- LLVM_DEBUG (llvm::dbgs ()
744- << " no conflict: op interace of reading op says 'no'\n " );
736+ LDBG () << " no conflict: op interace of reading op says 'no'" ;
745737 continue ;
746738 }
747739 }
@@ -751,39 +743,34 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
751743 options.dynCastBufferizableOp (conflictingWritingOp)) {
752744 if (bufferizableOp.isNotConflicting (uRead, uConflictingWrite,
753745 state)) {
754- LLVM_DEBUG (
755- llvm::dbgs ()
756- << " no conflict: op interace of writing op says 'no'\n " );
746+ LDBG () << " no conflict: op interace of writing op says 'no'" ;
757747 continue ;
758748 }
759749 }
760750 }
761751
762752 // Check all possible definitions.
763753 for (Value definition : definitions) {
764- LLVM_DEBUG ( llvm::dbgs ( ) << " * definition = " << definition << " \n " ) ;
754+ LDBG ( ) << " * definition = " << definition;
765755
766756 // No conflict if the conflicting write happens before the definition.
767757 if (Operation *defOp = definition.getDefiningOp ()) {
768758 if (happensBefore (conflictingWritingOp, defOp, domInfo)) {
769759 // conflictingWritingOp happens before defOp. No conflict.
770- LLVM_DEBUG (llvm::dbgs ()
771- << " no conflict: write happens before definition\n " );
760+ LDBG () << " no conflict: write happens before definition" ;
772761 continue ;
773762 }
774763 // No conflict if conflictingWritingOp is contained in defOp.
775764 if (defOp->isProperAncestor (conflictingWritingOp)) {
776- LLVM_DEBUG (
777- llvm::dbgs ()
778- << " no conflict: write is contained in definition\n " );
765+ LDBG () << " no conflict: write is contained in definition" ;
779766 continue ;
780767 }
781768 } else {
782769 auto bbArg = cast<BlockArgument>(definition);
783770 Block *block = bbArg.getOwner ();
784771 if (!block->findAncestorOpInBlock (*conflictingWritingOp)) {
785- LLVM_DEBUG ( llvm::dbgs () << " no conflict: definition is bbArg "
786- " and write happens outside of block\n " ) ;
772+ LDBG () << " no conflict: definition is bbArg "
773+ " and write happens outside of block" ;
787774 // conflictingWritingOp happens outside of the block. No
788775 // conflict.
789776 continue ;
@@ -795,16 +782,15 @@ hasReadAfterWriteInterference(const DenseSet<OpOperand *> &usesRead,
795782 AliasingValueList aliases = state.getAliasingValues (*uConflictingWrite);
796783 if (aliases.getNumAliases () == 1 &&
797784 aliases.getAliases ()[0 ].value == definition) {
798- LLVM_DEBUG (llvm::dbgs ()
799- << " no conflict: definition and write are same\n " );
785+ LDBG () << " no conflict: definition and write are same" ;
800786 continue ;
801787 }
802788
803789 // All requirements are met. Conflict found!
804790
805791 if (options.printConflicts )
806792 annotateConflict (uRead, uConflictingWrite, definition);
807- LLVM_DEBUG ( llvm::dbgs ( ) << " => RaW CONFLICT FOUND\n " ) ;
793+ LDBG ( ) << " => RaW CONFLICT FOUND" ;
808794 return true ;
809795 }
810796 }
@@ -958,7 +944,7 @@ wouldCreateWriteToNonWritableBuffer(OpOperand &operand,
958944 for (AliasingValue alias : state.getAliasingValues (operand))
959945 state.applyOnAliases (alias.value , checkReadOnly);
960946 if (foundReadOnly) {
961- LLVM_DEBUG ( llvm::dbgs ( ) << " => NOT WRITABLE\n " ) ;
947+ LDBG ( ) << " => NOT WRITABLE" ;
962948 return true ;
963949 }
964950
@@ -987,10 +973,9 @@ void OneShotAnalysisState::resetCache() {
987973static LogicalResult
988974bufferizableInPlaceAnalysisImpl (OpOperand &operand, OneShotAnalysisState &state,
989975 const DominanceInfo &domInfo) {
990- LLVM_DEBUG (
991- llvm::dbgs () << " //===-------------------------------------------===//\n "
992- << " Analyzing operand #" << operand.getOperandNumber ()
993- << " of " << *operand.getOwner () << " \n " );
976+ LDBG () << " //===-------------------------------------------===//\n "
977+ << " Analyzing operand #" << operand.getOperandNumber () << " of "
978+ << *operand.getOwner ();
994979
995980 bool foundInterference =
996981 wouldCreateWriteToNonWritableBuffer (operand, state) ||
@@ -1001,8 +986,7 @@ bufferizableInPlaceAnalysisImpl(OpOperand &operand, OneShotAnalysisState &state,
1001986 else
1002987 state.bufferizeInPlace (operand);
1003988
1004- LLVM_DEBUG (llvm::dbgs ()
1005- << " //===-------------------------------------------===//\n " );
989+ LDBG () << " //===-------------------------------------------===//" ;
1006990 return success ();
1007991}
1008992
0 commit comments