Skip to content

Commit 1f8ffbd

Browse files
[mlir][bufferize][NFC] Address review comments of D135420
These changes should have been landed as part of D135420. Differential Revision: https://reviews.llvm.org/D135438
1 parent 46ca425 commit 1f8ffbd

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,14 @@ static bool isMemoryWrite(Value value, const AnalysisState &state) {
430430
/// "writing_op", so op dominance can be used to compute the `happensBefore`
431431
/// relationship.
432432
///
433-
/// This functions finds the closest enclosing repetitive region of all buffer
434-
/// writes wrt. the given given tensor reads and writes. If this is the same
435-
/// region (nullptr in case of "no repetitive region" found at all), op
436-
/// dominance can be used. Otherwise, it cannot be used.
433+
/// Whether op dominance can be used or not is decided as follows: Find the
434+
/// closest enclosing repetitive region of all buffer writes wrt. the given
435+
/// tensor reads and writes. (The given sets of reads and writes contain the
436+
/// entire alias set.) In case of a read, we look at the op that defines the
437+
/// read value. In case of a write, we look at the op that is writing. If all of
438+
/// those ops are in the same closest enclosing repetitive region (nullptr in
439+
/// case of "no repetitive region" found at all), then op dominance can be used.
440+
/// Otherwise, it cannot be used.
437441
///
438442
/// Example: The common enclosing repetitive region is the scf.for loop.
439443
/// Op dominance can be used.
@@ -572,23 +576,36 @@ static bool hasReadAfterWriteInterference(
572576
// met for uConflictingWrite to be an actual conflict.
573577
Operation *conflictingWritingOp = uConflictingWrite->getOwner();
574578

575-
// No conflict if the readingOp dominates conflictingWritingOp, i.e., the
576-
// write is not visible when reading.
577-
//
578-
// Note: If ops are executed multiple times (e.g., because they are inside
579-
// a loop), there may be no meaningful `happensBefore` relationship.
580-
if (useDominance &&
581-
happensBefore(readingOp, conflictingWritingOp, domInfo))
582-
continue;
579+
// Inside of repetitive regions, ops may be executed multiple times and op
580+
// dominance cannot be used to rule out conflicts.
581+
if (useDominance) {
582+
// No conflict if the readingOp dominates conflictingWritingOp, i.e.,
583+
// the write is not visible when reading.
584+
//
585+
// Note: If ops are executed multiple times (e.g., because they are
586+
// inside a loop), there may be no meaningful `happensBefore`
587+
// relationship.
588+
if (happensBefore(readingOp, conflictingWritingOp, domInfo))
589+
continue;
583590

584-
// No conflict if the reading use equals the use of the conflicting write.
585-
// A use cannot conflict with itself.
586-
//
587-
// Note: Just being the same op is not enough. It has to be the same use.
588-
// Note: If the op is executed multiple times (e.g., because it is inside
589-
// a loop), it may be conflicting with itself.
590-
if (useDominance && uConflictingWrite == uRead)
591-
continue;
591+
// No conflict if the reading use equals the use of the conflicting
592+
// write. A use cannot conflict with itself.
593+
//
594+
// Note: Just being the same op is not enough. It has to be the same
595+
// use.
596+
// Note: If the op is executed multiple times (e.g., because it is
597+
// inside a loop), it may be conflicting with itself.
598+
if (uConflictingWrite == uRead)
599+
continue;
600+
601+
// Ops are not conflicting if they are in mutually exclusive regions.
602+
//
603+
// Note: If ops are executed multiple times (e.g., because they are
604+
// inside a loop), mutually exclusive regions may be executed
605+
// multiple times.
606+
if (insideMutuallyExclusiveRegions(readingOp, conflictingWritingOp))
607+
continue;
608+
}
592609

593610
// No conflict if the op interface says so.
594611
if (auto bufferizableOp = options.dynCastBufferizableOp(readingOp))
@@ -601,15 +618,6 @@ static bool hasReadAfterWriteInterference(
601618
if (bufferizableOp.isNotConflicting(uRead, uConflictingWrite, state))
602619
continue;
603620

604-
// Ops are not conflicting if they are in mutually exclusive regions.
605-
//
606-
// Note: If ops are executed multiple times (e.g., because they are inside
607-
// a loop), mutually exclusive regions may be executed multiple
608-
// times.
609-
if (useDominance &&
610-
insideMutuallyExclusiveRegions(readingOp, conflictingWritingOp))
611-
continue;
612-
613621
// Check all possible last writes.
614622
for (Value lastWrite : lastWrites) {
615623
// No conflict if the conflicting write happens before the last

0 commit comments

Comments
 (0)