Skip to content

Commit f1aa783

Browse files
[mlir][IR] Fix overload resolution on MSVC build (llvm#84589)
llvm#82629 added additional overloads to `replaceAllUsesWith` and `replaceUsesWithIf`. This caused a build breakage with MSVC when called with ops that can implicitly convert to `Value`. ``` external/llvm-project/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp(881): error C2666: 'mlir::RewriterBase::replaceAllUsesWith': 2 overloads have similar conversions external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(631): note: could be 'void mlir::RewriterBase::replaceAllUsesWith(mlir::Operation *,mlir::ValueRange)' external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(626): note: or 'void mlir::RewriterBase::replaceAllUsesWith(mlir::ValueRange,mlir::ValueRange)' external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(616): note: or 'void mlir::RewriterBase::replaceAllUsesWith(mlir::Value,mlir::Value)' external/llvm-project/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp(882): note: while trying to match the argument list '(mlir::tensor::ExtractSliceOp, T)' with [ T=mlir::Value ] ``` Note: The LLVM build bots (Linux and Windows) did not break, this seems to be an issue with `Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe`. This change renames the newly added overloads to `replaceAllOpUsesWith` and `replaceOpUsesWithIf`.
1 parent d4569d4 commit f1aa783

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,10 @@ class RewriterBase : public OpBuilder {
648648
for (auto it : llvm::zip(from, to))
649649
replaceAllUsesWith(std::get<0>(it), std::get<1>(it));
650650
}
651-
void replaceAllUsesWith(Operation *from, ValueRange to) {
651+
// Note: This function cannot be called `replaceAllUsesWith` because the
652+
// overload resolution, when called with an op that can be implicitly
653+
// converted to a Value, would be ambiguous.
654+
void replaceAllOpUsesWith(Operation *from, ValueRange to) {
652655
replaceAllUsesWith(from->getResults(), to);
653656
}
654657

@@ -662,19 +665,22 @@ class RewriterBase : public OpBuilder {
662665
void replaceUsesWithIf(ValueRange from, ValueRange to,
663666
function_ref<bool(OpOperand &)> functor,
664667
bool *allUsesReplaced = nullptr);
665-
void replaceUsesWithIf(Operation *from, ValueRange to,
666-
function_ref<bool(OpOperand &)> functor,
667-
bool *allUsesReplaced = nullptr) {
668+
// Note: This function cannot be called `replaceOpUsesWithIf` because the
669+
// overload resolution, when called with an op that can be implicitly
670+
// converted to a Value, would be ambiguous.
671+
void replaceOpUsesWithIf(Operation *from, ValueRange to,
672+
function_ref<bool(OpOperand &)> functor,
673+
bool *allUsesReplaced = nullptr) {
668674
replaceUsesWithIf(from->getResults(), to, functor, allUsesReplaced);
669675
}
670676

671677
/// Find uses of `from` within `block` and replace them with `to`. Also notify
672678
/// the listener about every in-place op modification (for every use that was
673679
/// replaced). The optional `allUsesReplaced` flag is set to "true" if all
674680
/// uses were replaced.
675-
void replaceUsesWithinBlock(Operation *op, ValueRange newValues, Block *block,
676-
bool *allUsesReplaced = nullptr) {
677-
replaceUsesWithIf(
681+
void replaceOpUsesWithinBlock(Operation *op, ValueRange newValues,
682+
Block *block, bool *allUsesReplaced = nullptr) {
683+
replaceOpUsesWithIf(
678684
op, newValues,
679685
[block](OpOperand &use) {
680686
return block->getParentOp()->isProperAncestor(use.getOwner());

mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ DecomposeLinalgOp::matchAndRewrite(GenericOp genericOp,
370370
scalarReplacements.push_back(
371371
residualGenericOpBody->getArgument(num + origNumInputs));
372372
bool allUsesReplaced = false;
373-
rewriter.replaceUsesWithinBlock(peeledScalarOperation, scalarReplacements,
374-
residualGenericOpBody, &allUsesReplaced);
373+
rewriter.replaceOpUsesWithinBlock(peeledScalarOperation, scalarReplacements,
374+
residualGenericOpBody, &allUsesReplaced);
375375
assert(!allUsesReplaced &&
376376
"peeled scalar operation is erased when it wasnt expected to be");
377377
}

mlir/lib/IR/PatternMatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void RewriterBase::replaceOp(Operation *op, ValueRange newValues) {
122122
rewriteListener->notifyOperationReplaced(op, newValues);
123123

124124
// Replace all result uses. Also notifies the listener of modifications.
125-
replaceAllUsesWith(op, newValues);
125+
replaceAllOpUsesWith(op, newValues);
126126

127127
// Erase op and notify listener.
128128
eraseOp(op);
@@ -141,7 +141,7 @@ void RewriterBase::replaceOp(Operation *op, Operation *newOp) {
141141
rewriteListener->notifyOperationReplaced(op, newOp);
142142

143143
// Replace all result uses. Also notifies the listener of modifications.
144-
replaceAllUsesWith(op, newOp->getResults());
144+
replaceAllOpUsesWith(op, newOp->getResults());
145145

146146
// Erase op and notify listener.
147147
eraseOp(op);

mlir/lib/Transforms/Utils/RegionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ SmallVector<Value> mlir::makeRegionIsolatedFromAbove(
161161
rewriter.setInsertionPointToStart(newEntryBlock);
162162
for (auto *clonedOp : clonedOperations) {
163163
Operation *newOp = rewriter.clone(*clonedOp, map);
164-
rewriter.replaceUsesWithIf(clonedOp, newOp->getResults(), replaceIfFn);
164+
rewriter.replaceOpUsesWithIf(clonedOp, newOp->getResults(), replaceIfFn);
165165
}
166166
rewriter.mergeBlocks(
167167
entryBlock, newEntryBlock,

0 commit comments

Comments
 (0)