@@ -624,10 +624,9 @@ class ModifyOperationRewrite : public OperationRewrite {
624
624
class ReplaceOperationRewrite : public OperationRewrite {
625
625
public:
626
626
ReplaceOperationRewrite (ConversionPatternRewriterImpl &rewriterImpl,
627
- Operation *op, const TypeConverter *converter,
628
- bool changedResults)
627
+ Operation *op, const TypeConverter *converter)
629
628
: OperationRewrite(Kind::ReplaceOperation, rewriterImpl, op),
630
- converter (converter), changedResults(changedResults) {}
629
+ converter (converter) {}
631
630
632
631
static bool classof (const IRRewrite *rewrite) {
633
632
return rewrite->getKind () == Kind::ReplaceOperation;
@@ -641,15 +640,10 @@ class ReplaceOperationRewrite : public OperationRewrite {
641
640
642
641
const TypeConverter *getConverter () const { return converter; }
643
642
644
- bool hasChangedResults () const { return changedResults; }
645
-
646
643
private:
647
644
// / An optional type converter that can be used to materialize conversions
648
645
// / between the new and old values if necessary.
649
646
const TypeConverter *converter;
650
-
651
- // / A boolean flag that indicates whether result types have changed or not.
652
- bool changedResults;
653
647
};
654
648
655
649
class CreateOperationRewrite : public OperationRewrite {
@@ -941,6 +935,7 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
941
935
// / to modify/access them is invalid rewriter API usage.
942
936
SetVector<Operation *> replacedOps;
943
937
938
+ // / A set of all unresolved materializations.
944
939
DenseSet<Operation *> unresolvedMaterializations;
945
940
946
941
// / The current type converter, or nullptr if no type converter is currently
@@ -1383,17 +1378,13 @@ void ConversionPatternRewriterImpl::notifyOpReplaced(Operation *op,
1383
1378
assert (newValues.size () == op->getNumResults ());
1384
1379
assert (!ignoredOps.contains (op) && " operation was already replaced" );
1385
1380
1386
- // Track if any of the results changed, e.g. erased and replaced with null.
1387
- bool resultChanged = false ;
1388
-
1389
1381
// Create mappings for each of the new result values.
1390
1382
for (auto [newValue, result] : llvm::zip (newValues, op->getResults ())) {
1391
1383
if (!newValue) {
1392
1384
// This result was dropped and no replacement value was provided.
1393
1385
if (unresolvedMaterializations.contains (op)) {
1394
1386
// Do not create another materializations if we are erasing a
1395
1387
// materialization.
1396
- resultChanged = true ;
1397
1388
continue ;
1398
1389
}
1399
1390
@@ -1406,11 +1397,9 @@ void ConversionPatternRewriterImpl::notifyOpReplaced(Operation *op,
1406
1397
1407
1398
// Remap, and check for any result type changes.
1408
1399
mapping.map (result, newValue);
1409
- resultChanged |= (newValue.getType () != result.getType ());
1410
1400
}
1411
1401
1412
- appendRewrite<ReplaceOperationRewrite>(op, currentTypeConverter,
1413
- resultChanged);
1402
+ appendRewrite<ReplaceOperationRewrite>(op, currentTypeConverter);
1414
1403
1415
1404
// Mark this operation and all nested ops as replaced.
1416
1405
op->walk ([&](Operation *op) { replacedOps.insert (op); });
@@ -2585,7 +2574,7 @@ LogicalResult OperationConverter::legalizeConvertedOpResultTypes(
2585
2574
for (unsigned i = 0 ; i < rewriterImpl.rewrites .size (); ++i) {
2586
2575
auto *opReplacement =
2587
2576
dyn_cast<ReplaceOperationRewrite>(rewriterImpl.rewrites [i].get ());
2588
- if (!opReplacement || !opReplacement-> hasChangedResults () )
2577
+ if (!opReplacement)
2589
2578
continue ;
2590
2579
Operation *op = opReplacement->getOperation ();
2591
2580
for (OpResult result : op->getResults ()) {
0 commit comments