Add new node pattern matching boilerplate & make use of it#5284
Open
asl wants to merge 7 commits intop4lang:mainfrom
Open
Add new node pattern matching boilerplate & make use of it#5284asl wants to merge 7 commits intop4lang:mainfrom
asl wants to merge 7 commits intop4lang:mainfrom
Conversation
Contributor
asl
commented
May 18, 2025
- Add node pattern matching implementation similar to LLVM's IR pattern matching:
- More flexible & generic than present pattern matching, could be further extended if necessary
- Can optionally bind nodes in the pattern to local variables
- Can match types, can perform deferred matching (e.g. refine the match further on)
- Switch reassociation and strength reduction to this new implementation
- Extend reassociation (and document its limitations)
- Add couple more strength reduction patterns
Signed-off-by: Anton Korobeynikov <[email protected]>
…ation Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
ChrisDodd
reviewed
May 19, 2025
| const IR::Constant *c1, *c2; | ||
| const IR::Expression *e; | ||
| if (match(root, | ||
| m_BinOp(m_AllOf(m_BinOp(lhs), m_BinOp(m_Expr(e), m_Constant(c1))), m_Constant(c2))) && |
Contributor
There was a problem hiding this comment.
This seems far inferior to the IR::Pattern matching, which is much simpler and clearer
Contributor
Author
There was a problem hiding this comment.
Will you please be more specific? How I can e.g. match if operand has particular type in IR::Pattern? Or check if two operands are the same? etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.