Skip to content

Conversation

@mgehre-amd
Copy link
Collaborator

@mgehre-amd mgehre-amd commented Nov 12, 2025

Add action to enable listener for RewriterBase::replaceOp, RewriterBase::replaceAllUsesWith and friends.

@mgehre-amd mgehre-amd force-pushed the matthias.replace_op_action_public branch from a84528d to a1da90b Compare November 13, 2025 07:51
@mgehre-amd mgehre-amd marked this pull request as ready for review November 13, 2025 07:51
/// Find uses of `from` and replace them with `to`. Also notify the listener
/// about every in-place op modification (for every use that was replaced).
void replaceAllUsesWith(Value from, Value to) {
if (auto *fromOp = from.getDefiningOp())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also notify the listener
  /// about every in-place op modification (for every use that was replaced).

Was this not up-to-date? Or is an action something else than the listener?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main question is also whats the difference between an action and a listener

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RewriterBase supports attaching listeners, and the MLIRContext supports action handlers. In this PR, we use the action handlers on the MLIRContext, which allow us to observe across all passes without modifying each.

Copy link
Contributor

@cferry-AMD cferry-AMD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceAllUsesWith(ValueRange, ValueRange) should also be modified, shouldn't it?

@mgehre-amd
Copy link
Collaborator Author

replaceAllUsesWith(ValueRange, ValueRange)
this calls the replaceAllUsesWith(Value from, Value to), which calls the action here

void replaceAllUsesWith(ValueRange from, ValueRange to) {
    assert(from.size() == to.size() && "incorrect number of replacements");
    for (auto it : llvm::zip(from, to))
      replaceAllUsesWith(std::get<0>(it), std::get<1>(it));
  }

Copy link
Contributor

@cferry-AMD cferry-AMD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the claraifications, that looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants