Op replacements are not notified via listener in analysisConversion

Hello,

I am trying to write a pass in MLIR that requires to do an analysisConversion with some patterns and I want to get notified on when an op is replaced and to what op.

The applyAnalysisConversion method already takes a config and one can add a listener to it, so that is what I did, with notifyPatternBegin/End and notifyOperationReplaced/Erased virtual methods implemented.

However it seems that only the notifyPatternBegin/End is getting called, not those operation related callbacks. Is this expected?

1 Like

This is related to an issue I brought up in the Discord. When using the dialect conversion framework, ops that do not produce results which are replaced with another op (or multiple) are only called with the notifyOperationReplaced(Operation *op, ValueRange replacement) version of notifyOpReplaced, which doesn’t work since there are no replacement values.

I think we may need to do a lot of work to fix how listeners are used in dialect conversion, or at least document the deficiencies.

Yes, this is expected, but the documentation should be improved:

  /// An optional listener that is notified about all IR modifications in case
  /// dialect conversion succeeds. If the dialect conversion fails and no IR
  /// modifications are visible (i.e., they were all rolled back), no
  /// notifications are sent.

When you run an “analysis conversion”, no IR modifications are visible when the analysis has finished (i.e., no IR was changed). So no notifications are sent.

I think we may need to do a lot of work to fix how listeners are used in dialect conversion, or at least document the deficiencies.

I am working on a simpler dialect conversion driver that addresses some of the current deficiencies. (Not the one mentioned here, because the new driver does not have an “analysis” mode.)