File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -782,6 +782,12 @@ class ConversionPatternRewriter final : public PatternRewriter {
782
782
783
783
// / Replace all the uses of the block argument `from` with `to`. This
784
784
// / function supports both 1:1 and 1:N replacements.
785
+ // /
786
+ // / Note: If `allowPatternRollback` is set to "true", this function replaces
787
+ // / all current and future uses of the block argument. This same block
788
+ // / block argument must not be replaced multiple times. Uses are not replaced
789
+ // / immediately but in a delayed fashion. Patterns may still see the original
790
+ // / uses when inspecting IR.
785
791
void replaceUsesOfBlockArgument (BlockArgument from, ValueRange to);
786
792
787
793
// / Return the converted value of 'key' with a type defined by the type
Original file line number Diff line number Diff line change @@ -1132,6 +1132,11 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
1132
1132
IRRewriter notifyingRewriter;
1133
1133
1134
1134
#ifndef NDEBUG
1135
+ // / A set of replaced block arguments. This set is for debugging purposes
1136
+ // / only and it is maintained only if `allowPatternRollback` is set to
1137
+ // / "true".
1138
+ DenseSet<BlockArgument> replacedArgs;
1139
+
1135
1140
// / A set of operations that have pending updates. This tracking isn't
1136
1141
// / strictly necessary, and is thus only active during debug builds for extra
1137
1142
// / verification.
@@ -1892,6 +1897,19 @@ void ConversionPatternRewriterImpl::replaceUsesOfBlockArgument(
1892
1897
return ;
1893
1898
}
1894
1899
1900
+ #ifndef NDEBUG
1901
+ // Make sure that a block argument is not replaced multiple times. In
1902
+ // rollback mode, `replaceUsesOfBlockArgument` replaces not only all current
1903
+ // uses of the given block argument, but also all future uses that may be
1904
+ // introduced by future pattern applications. Therefore, it does not make
1905
+ // sense to call `replaceUsesOfBlockArgument` multiple times with the same
1906
+ // block argument. Doing so would overwrite the mapping and mess with the
1907
+ // internal state of the dialect conversion driver.
1908
+ assert (!replacedArgs.contains (from) &&
1909
+ " attempting to replace a block argument that was already replaced" );
1910
+ replacedArgs.insert (from);
1911
+ #endif // NDEBUG
1912
+
1895
1913
appendRewrite<ReplaceBlockArgRewrite>(from.getOwner (), from, converter);
1896
1914
mapping.map (from, to);
1897
1915
}
You can’t perform that action at this time.
0 commit comments