This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OperationEquivalence] Add an extra callback to hook operation equivalence check
AcceptedPublic

Authored by uenoku on Jul 18 2023, 4:11 AM.

Details

Summary

This patch adds an extract callback checkOpStructureEquivalent to a method OperationEquivalence::isEquivalentTo so that users can use customize equivalence regarding structural properties of operations.

I'm not sure that "structural properties" is a best term to describe operation information used here. I think just "properties" is better but I added "structural" to clearly distinguish from operation properties.

This patch is preparation to provide dialect interface for CSE https://discourse.llvm.org/t/rfc-dialectinterface-for-cse/71831

Diff Detail

Event Timeline

uenoku created this revision.Jul 18 2023, 4:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 4:11 AM
uenoku requested review of this revision.Jul 18 2023, 4:11 AM
uenoku updated this revision to Diff 541447.Jul 18 2023, 4:14 AM
uenoku retitled this revision from [mlir][OperationEquivalence] Add an extra callback to hook structural property equivalence check to [mlir][OperationEquivalence] Add an extra callback to hook operation equivalence check.

The change makes sense but I wonder at this point whether OperationEquivalence should transition to an abstract class.

mlir/include/mlir/IR/OperationSupport.h
1209

I'm starting to wonder if callbacks is the right design for OperationEquivalence at this point. Users are basically passing in a vtable for each function call.

uenoku added inline comments.Jul 21 2023, 5:20 AM
mlir/include/mlir/IR/OperationSupport.h
1209

It makes sense to me to move away from passing around callbacks. I kind feel it would be sufficient to just make these callbacks as members of OperationalEquivalence class since these callbacks don't mutually call each other. I think in either way it will be necessary to define a helper class to take callbacks as members when OperationalEquivalence is implemented as abstract class.

Mogball added inline comments.Jul 21 2023, 3:00 PM
mlir/include/mlir/IR/OperationSupport.h
1209

I think in either way it will be necessary to define a helper class to take callbacks as members when OperationalEquivalence is implemented as abstract class.

Why so? I am imagining that users of OperationEquivalence take an abstract class and then users provide a specific subclass with the relevant methods implemented. If you think the callbacks are still cleaner, then this works for me too.

uenoku marked an inline comment as not done.Jul 24 2023, 5:30 AM
uenoku added inline comments.
mlir/include/mlir/IR/OperationSupport.h
1209

I thought ergonomically it would be better to just pass callbacks since users will have to define struct and override relevant methods even for basic use cases but I don't have strong opinion here. Abstract class implementation does work well in our CIRCT use case so I'll implement with abstract class :)

Mogball accepted this revision.Jul 25 2023, 8:16 AM
This revision is now accepted and ready to land.Jul 25 2023, 8:16 AM