Skip to content

Commit 9b4aa86

Browse files
[mlir][Transforms] Add listener support to dialect conversion
1 parent 4ea3fc3 commit 9b4aa86

File tree

4 files changed

+302
-55
lines changed

4 files changed

+302
-55
lines changed

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,39 @@ struct ConversionConfig {
10911091
/// IR during an analysis conversion and only pre-existing operations are
10921092
/// added to the set.
10931093
DenseSet<Operation *> *legalizableOps = nullptr;
1094+
1095+
/// An optional listener that is notified about all IR modifications in case
1096+
/// dialect conversion succeeds. If the dialect conversion fails and no IR
1097+
/// modifications are visible (i.e., they were all rolled back), no
1098+
/// notifications are sent.
1099+
///
1100+
/// Note: Notifications are sent in a delayed fashion, when the dialect
1101+
/// conversion is guaranteed to succeed. At that point, some IR modifications
1102+
/// may already have been materialized. Consequently, operations/blocks that
1103+
/// are passed to listener callbacks should not be accessed. (Ops/blocks are
1104+
/// guaranteed to be valid pointers and accessing op names is allowed. But
1105+
/// there are no guarantees about the state of ops/blocks at the time that a
1106+
/// callback is triggered.)
1107+
///
1108+
/// Example: Consider a dialect conversion a new op ("test.foo") is created
1109+
/// and inserted, and later moved to another block. (Moving ops also triggers
1110+
/// "notifyOperationInserted".)
1111+
///
1112+
/// (1) notifyOperationInserted: "test.foo" (into block "b1")
1113+
/// (2) notifyOperationInserted: "test.foo" (moved to another block "b2")
1114+
///
1115+
/// When querying "op->getBlock()" during the first "notifyOperationInserted",
1116+
/// "b2" would be returned because "moving an op" is a kind of rewrite that is
1117+
/// immediately performed by the dialect conversion (and rolled back upon
1118+
/// failure).
1119+
//
1120+
// Note: When receiving a "notifyBlockInserted"/"notifyOperationInserted"
1121+
// callback, the previous region/block is provided to the callback, but not
1122+
// the iterator pointing to the exact location within the region/block. That
1123+
// is because these notifications are sent with a delay (after the IR has
1124+
// already been modified) and iterators into past IR state cannot be
1125+
// represented at the moment.
1126+
RewriterBase::Listener *listener = nullptr;
10941127
};
10951128

10961129
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)