This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Add `OpBuilder::attachScopedListener` and make `setListener` protected
Needs ReviewPublic

Authored by springerm on Jul 18 2023, 8:37 AM.

Details

Summary

OpBuilder::setListener is dangerous: users can accidentally replace a listener from an OpBuilder that was passed to them.

This revision makes setListener protected: it should only be used from the constructor of derived classes (typically rewriters that set up themselves as listeners).

This revision also adds a new function attachScopedListener that can be used to attach additional listeners in a safe way. Detaching existing listener (whether accidental or on purpose) is no longer possible with the public OpBuilder API.

Depends On: D155609

Diff Detail