@@ -1856,7 +1856,8 @@ class OperationLegalizer {
1856
1856
using LegalizationAction = ConversionTarget::LegalizationAction;
1857
1857
1858
1858
OperationLegalizer (const ConversionTarget &targetInfo,
1859
- const FrozenRewritePatternSet &patterns);
1859
+ const FrozenRewritePatternSet &patterns,
1860
+ const ConversionConfig &config);
1860
1861
1861
1862
// / Returns true if the given operation is known to be illegal on the target.
1862
1863
bool isIllegal (Operation *op) const ;
@@ -1948,12 +1949,16 @@ class OperationLegalizer {
1948
1949
1949
1950
// / The pattern applicator to use for conversions.
1950
1951
PatternApplicator applicator;
1952
+
1953
+ // / Dialect conversion configuration.
1954
+ const ConversionConfig &config;
1951
1955
};
1952
1956
} // namespace
1953
1957
1954
1958
OperationLegalizer::OperationLegalizer (const ConversionTarget &targetInfo,
1955
- const FrozenRewritePatternSet &patterns)
1956
- : target(targetInfo), applicator(patterns) {
1959
+ const FrozenRewritePatternSet &patterns,
1960
+ const ConversionConfig &config)
1961
+ : target(targetInfo), applicator(patterns), config(config) {
1957
1962
// The set of patterns that can be applied to illegal operations to transform
1958
1963
// them into legal ones.
1959
1964
DenseMap<OperationName, LegalizationPatterns> legalizerPatterns;
@@ -2098,7 +2103,10 @@ OperationLegalizer::legalizeWithPattern(Operation *op,
2098
2103
2099
2104
// Functor that returns if the given pattern may be applied.
2100
2105
auto canApply = [&](const Pattern &pattern) {
2101
- return canApplyPattern (op, pattern, rewriter);
2106
+ bool canApply = canApplyPattern (op, pattern, rewriter);
2107
+ if (canApply && config.listener )
2108
+ config.listener ->notifyPatternBegin (pattern, op);
2109
+ return canApply;
2102
2110
};
2103
2111
2104
2112
// Functor that cleans up the rewriter state after a pattern failed to match.
@@ -2115,6 +2123,8 @@ OperationLegalizer::legalizeWithPattern(Operation *op,
2115
2123
rewriterImpl.config .notifyCallback (diag);
2116
2124
}
2117
2125
});
2126
+ if (config.listener )
2127
+ config.listener ->notifyPatternEnd (pattern, failure ());
2118
2128
rewriterImpl.resetState (curState);
2119
2129
appliedPatterns.erase (&pattern);
2120
2130
};
@@ -2127,6 +2137,8 @@ OperationLegalizer::legalizeWithPattern(Operation *op,
2127
2137
appliedPatterns.erase (&pattern);
2128
2138
if (failed (result))
2129
2139
rewriterImpl.resetState (curState);
2140
+ if (config.listener )
2141
+ config.listener ->notifyPatternEnd (pattern, result);
2130
2142
return result;
2131
2143
};
2132
2144
@@ -2502,7 +2514,8 @@ struct OperationConverter {
2502
2514
const FrozenRewritePatternSet &patterns,
2503
2515
const ConversionConfig &config,
2504
2516
OpConversionMode mode)
2505
- : opLegalizer(target, patterns), config(config), mode(mode) {}
2517
+ : config(config), opLegalizer(target, patterns, this ->config),
2518
+ mode(mode) {}
2506
2519
2507
2520
// / Converts the given operations to the conversion target.
2508
2521
LogicalResult convertOperations (ArrayRef<Operation *> ops);
@@ -2539,12 +2552,12 @@ struct OperationConverter {
2539
2552
ConversionPatternRewriterImpl &rewriterImpl,
2540
2553
const DenseMap<Value, SmallVector<Value>> &inverseMapping);
2541
2554
2542
- // / The legalizer to use when converting operations.
2543
- OperationLegalizer opLegalizer;
2544
-
2545
2555
// / Dialect conversion configuration.
2546
2556
ConversionConfig config;
2547
2557
2558
+ // / The legalizer to use when converting operations.
2559
+ OperationLegalizer opLegalizer;
2560
+
2548
2561
// / The conversion mode to use when legalizing operations.
2549
2562
OpConversionMode mode;
2550
2563
};
0 commit comments