-
Notifications
You must be signed in to change notification settings - Fork 368
[Synth] Add structural hashing pass for AIG/MIG operations #8962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit implements a domain-specific structural hashing (CSE) pass for Synth dialect operations (AIG/MIG), providing more aggressive optimization than MLIR's general CSE pass. The pass performs structural hashing for synth.aig.and_inv and synth.mig.maj_inv operations, with operand sorting based on IR postions for better canonicalization and inversion-aware hashing that properly handles AIG inversion flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only had 30 mins to review - will continue in the morning
/// Maps inverted values to their non-inverted equivalents for propagation. | ||
DenseMap<Value, Value> inversion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: struggled to understand what is meant by "for propagation" - would it be possible to add a small example in the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, totally!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - cannot say I've fully understood how the algorithm works so will have to read the papers from the field. Only comment would be to see if there's a way to provide examples to guide understanding - although the tests are very useful to see the capabilities.
Non-Blocking: As the available passes grow - would be good to expand documentation to understand the capabilities of different passes?
// Topologically sort target ops within the block. | ||
return !isa<circt::synth::aig::AndInverterOp, | ||
circt::synth::mig::MajorityInverterOp>(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Comment doesn't seem to match function?
pm.addPass(createStructuralHash()); | ||
pm.addPass(createSimpleCanonicalizerPass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: is there an argument for running strash after canonicalization - does canonicalization expose more opportunities? e.g. constant folding 1 & x -> x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, strash would help canonicalization (vice-versa). I added another run of strash after canonicalization.
Thank you for the review! Section 2.3 in https://people.eecs.berkeley.edu/~alanmi/publications/2005/tech05_fraigs.pdf briefly mentions Structural hashing. The current implementation probably corresponds to the most basic one-level structural hashing. This is still stronger than MLIR's CSE pass, e.g. MLIR one doesn't use commutativity (a+b and b+a are not CSE'd). https://circt.llvm.org/docs/Passes/ has a list of passes in CIRCT FYI (Synth was missing but should appear tomorrow f6b70b9). Also I'll describe Synth rational doc. |
This commit implements a domain-specific structural hashing (CSE) pass for Synth dialect operations (AIG/MIG), providing more aggressive optimization than MLIR's general CSE pass, e.g:
The pass performs structural hashing for synth.aig.and_inv and synth.mig.maj_inv operations, with operand sorting based on IR positions for better canonicalization and inversion-aware hashing that properly handles AIG/MIG inversion flags.
Basically this corresponds to ABC's
strash
command.