[MLIR] Fix dialect conversion cancelRootUpdate

Fix dialect conversion ConversionPatternRewriter::cancelRootUpdate: the
erasure of operations here from the list of root update was off by one.
Should have been:
```
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it - 1));
```
instead of
```
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it));
```

or more directly:
```
rootUpdates.erase(it.base() - 1)
```

While on this, add an assertion to improve dev experience when a cancel is
called on an op on which a root update hasn't been started.

Differential Revision: https://reviews.llvm.org/D105397
This commit is contained in:
Uday Bondhugula 2021-07-03 21:37:00 +05:30
parent 17b701c43c
commit 0c29f45ac9
1 changed files with 4 additions and 2 deletions

View File

@ -1484,7 +1484,9 @@ void ConversionPatternRewriter::cancelRootUpdate(Operation *op) {
auto stateHasOp = [op](const auto &it) { return it.getOperation() == op; };
auto &rootUpdates = impl->rootUpdates;
auto it = llvm::find_if(llvm::reverse(rootUpdates), stateHasOp);
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it));
assert(it != rootUpdates.rend() && "no root update started on op");
int updateIdx = std::prev(rootUpdates.rend()) - it;
rootUpdates.erase(rootUpdates.begin() + updateIdx);
}
/// PatternRewriter hook for notifying match failure reasons.
@ -2049,7 +2051,7 @@ void OperationLegalizer::computeLegalizationGraphBenefit(
orderedPatternList = anyOpLegalizerPatterns;
// If the pattern is not found, then it was removed and cannot be matched.
auto it = llvm::find(orderedPatternList, &pattern);
auto *it = llvm::find(orderedPatternList, &pattern);
if (it == orderedPatternList.end())
return PatternBenefit::impossibleToMatch();