-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Transforms] Improve replaceOpWithMultiple
API
#132608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthias-springer
merged 1 commit into
main
from
users/matthias-springer/replace_op_with_multiple_overloads
Mar 28, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,10 @@ struct ConversionValueMapping { | |
} | ||
} | ||
|
||
void map(Value oldVal, SmallVector<Value> &&newVal) { | ||
map(ValueVector{oldVal}, ValueVector(std::move(newVal))); | ||
} | ||
|
||
/// Drop the last mapping for the given values. | ||
void erase(const ValueVector &value) { mapping.erase(value); } | ||
|
||
|
@@ -946,7 +950,8 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener { | |
OpBuilder::InsertPoint previous) override; | ||
|
||
/// Notifies that an op is about to be replaced with the given values. | ||
void notifyOpReplaced(Operation *op, ArrayRef<ValueRange> newValues); | ||
void notifyOpReplaced(Operation *op, | ||
SmallVector<SmallVector<Value>> &&newValues); | ||
|
||
/// Notifies that a block is about to be erased. | ||
void notifyBlockIsBeingErased(Block *block); | ||
|
@@ -1519,7 +1524,7 @@ void ConversionPatternRewriterImpl::notifyOperationInserted( | |
} | ||
|
||
void ConversionPatternRewriterImpl::notifyOpReplaced( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is also a sink function i.e. needs to at the very least take |
||
Operation *op, ArrayRef<ValueRange> newValues) { | ||
Operation *op, SmallVector<SmallVector<Value>> &&newValues) { | ||
assert(newValues.size() == op->getNumResults()); | ||
assert(!ignoredOps.contains(op) && "operation was already replaced"); | ||
|
||
|
@@ -1561,7 +1566,7 @@ void ConversionPatternRewriterImpl::notifyOpReplaced( | |
// Remap result to replacement value. | ||
if (repl.empty()) | ||
continue; | ||
mapping.map(result, repl); | ||
mapping.map(static_cast<Value>(result), std::move(repl)); | ||
} | ||
|
||
appendRewrite<ReplaceOperationRewrite>(op, currentTypeConverter); | ||
|
@@ -1639,35 +1644,31 @@ void ConversionPatternRewriter::replaceOp(Operation *op, ValueRange newValues) { | |
impl->logger.startLine() | ||
<< "** Replace : '" << op->getName() << "'(" << op << ")\n"; | ||
}); | ||
SmallVector<ValueRange> newVals; | ||
for (size_t i = 0; i < newValues.size(); ++i) { | ||
if (newValues[i]) { | ||
newVals.push_back(newValues.slice(i, 1)); | ||
} else { | ||
newVals.push_back(ValueRange()); | ||
} | ||
} | ||
impl->notifyOpReplaced(op, newVals); | ||
SmallVector<SmallVector<Value>> newVals = | ||
llvm::map_to_vector(newValues, [](Value v) -> SmallVector<Value> { | ||
return v ? SmallVector<Value>{v} : SmallVector<Value>(); | ||
}); | ||
impl->notifyOpReplaced(op, std::move(newVals)); | ||
} | ||
|
||
void ConversionPatternRewriter::replaceOpWithMultiple( | ||
Operation *op, ArrayRef<ValueRange> newValues) { | ||
Operation *op, SmallVector<SmallVector<Value>> &&newValues) { | ||
assert(op->getNumResults() == newValues.size() && | ||
"incorrect # of replacement values"); | ||
LLVM_DEBUG({ | ||
impl->logger.startLine() | ||
<< "** Replace : '" << op->getName() << "'(" << op << ")\n"; | ||
}); | ||
impl->notifyOpReplaced(op, newValues); | ||
impl->notifyOpReplaced(op, std::move(newValues)); | ||
} | ||
|
||
void ConversionPatternRewriter::eraseOp(Operation *op) { | ||
LLVM_DEBUG({ | ||
impl->logger.startLine() | ||
<< "** Erase : '" << op->getName() << "'(" << op << ")\n"; | ||
}); | ||
SmallVector<ValueRange> nullRepls(op->getNumResults(), {}); | ||
impl->notifyOpReplaced(op, nullRepls); | ||
SmallVector<SmallVector<Value>> nullRepls(op->getNumResults(), {}); | ||
impl->notifyOpReplaced(op, std::move(nullRepls)); | ||
} | ||
|
||
void ConversionPatternRewriter::eraseBlock(Block *block) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.