1. Mar 12, 2024
  2. Mar 11, 2024
    • Matthias Springer's avatar
      [mlir][Transforms] Support `replaceAllUsesWith` in dialect conversion · 15c5ef47
      Matthias Springer authored
      This commit adds support for `RewriterBase::replaceAllUsesWith` to the dialect conversion. Uses are not immediately replaced, but in a delayed fashion during the "commit" phase. No type conversions are performed; this is consistent with `ConversionPatternRewriter::replaceUsesOfBlockArgument`.
      
      - `RewriterBase::replaceAllUsesWith` is now virtual, so that it can be overridden in the dialect conversion. Note: `RewriterBase::replaceOp` can now be turned into a non-virtual function in a follow-up commit.
      - `ConversionPatternRewriter::replaceUsesOfBlockArgument` is generalized to `ConversionPatternRewriter::replaceAllUsesWith`, following the same implementation strategy.
      - A new kind of "IR rewrite" is added: `ValueRewrite` with `ReplaceAllUsesRewrite` (replacing `ReplaceBlockArgRewrite`) as the only value rewrite for now.
      - `replacedOps` is renamed to `erasedOps` to better capture its meaning.
      
      BEGIN_PUBLIC
      No public commit message needed for presubmit.
      END_PUBLIC
      15c5ef47
    • Matthias Springer's avatar
      [mlir][IR][NFC] Make `replaceAllUsesWith` non-templatized · e70c754e
      Matthias Springer authored
      Turn `RewriterBase::replaceAllUsesWith` into a non-templatized implementation, so that it can be made virtual and be overridden in the `ConversionPatternRewriter` in a subsequent change.
      
      This change is in preparation of adding dialect conversion support for `replaceAllUsesWith`.
      e70c754e
    • Matthias Springer's avatar
      [mlir][IR] Trigger `notifyOperationReplaced` on `replaceAllOpUsesWith` · 7b93ec38
      Matthias Springer authored
      Before this change: `notifyOperationReplaced` was triggered when calling `RewriteBase::replaceOp`.
      After this change: `notifyOperationReplaced` is triggered when `RewriterBase::replaceAllOpUsesWith` or `RewriterBase::replaceOp` is called.
      
      Until now, every `notifyOperationReplaced` was always sent together with a `notifyOperationErased`, which made that `notifyOperationErased` callback irrelevant. More importantly, when a user called `RewriterBase::replaceAllOpUsesWith`+`RewriterBase::eraseOp` instead of `RewriterBase::replaceOp`, no `notifyOperationReplaced` callback was sent, even though the two notations are semantically equivalent. As an example, this can be a problem when applying patterns with the transform dialect because the `TrackingListener` will only see the `notifyOperationErased` callback and the payload op is dropped from the mappings.
      
      Note: It is still possible to write semantically equivalent code that does not trigger a `notifyOperationReplaced` (e.g., when op results are replaced one-by-one), but this commit already improves the situation a lot.
      7b93ec38
  3. Mar 09, 2024