Repository navigation
Fix iteration over op class with nested sub op classes - #149
Merged
Flakebi merged 2 commits intoNov 13, 2026
Merged
Conversation
Op classes can be nested: an op class may have another op class as its superclass, so that concrete ops are members of an inner op class, which in turn is a member of an outer one. Add a nested op class to the test dialect and tests covering it. This exposes a bug: visiting an op class only covers the ops that are direct members of that op class, silently skipping the ops of nested op classes. This is because visiting is based on OpDescription::getAll, which is generated from the list of ops registered with an op class, and ops are only registered with their immediate superclass. classof does not have this problem, as it recurses into nested op classes. isa<> and visiting therefore disagree for nested op classes. The new test asserts the current, wrong behavior and is marked with a FIXME. It is fixed in the next commit.
Visiting an op class only covered the ops that are direct members of that op class, silently skipping the ops of nested op classes. Visiting is based on OpDescription::getAll, which is generated from the list of ops registered with an op class. Ops are only registered with their immediate superclass, so for a nested op class hierarchy, the generated array of the outer op class was missing the ops of the inner ones. classof does not have this problem, as it recurses into nested op classes, so isa<> and visiting disagreed. Collect the ops of nested op classes when generating getAll, which makes visiting agree with isa<> again. The generated code for the example dialect is unchanged, as it does not contain nested op classes.
Contributor
Author
|
Can someone with permissions please help merge this (or grant me permissions to do so)? Thanks! |
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.
Op classes allow to define a hierarchy of parent op classes that may contain multiple concrete ops.
This allows to reduce redundancy in the table gen definition, where e.g. arguments can be defined on the op class.
It also allows to simplify client code by allowing to iterate over an op class without having to explicitly list all contained concrete ops. It is also possible to check with
isa<OpClassName>whether a given instruction belongs to an op class, again without explicitly listing all contained concrete ops.This patch fixes a bug with the iteration part: We were only iterating over immediate child ops, but not child ops of nested op classes.
The first commit precommits a test demonstrating the issue, the second commit fixes it.
The
isa<..>functionality was already correctly working for nested op classes, this patch also adds test coverage for that.