Skip to content

Fix iteration over op class with nested sub op classes - #149

Merged
Flakebi merged 2 commits into
GPUOpen-Drivers:devfrom
jasilvanus:jsilvanu/fix-nested-op-class
Nov 13, 2026
Merged

Flakebi merged 2 commits into
GPUOpen-Drivers:devfrom
jasilvanus:jsilvanu/fix-nested-op-class

Conversation

@jasilvanus

Copy link
Copy Markdown
Contributor

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.

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.

@Flakebi Flakebi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@jasilvanus

Copy link
Copy Markdown
Contributor Author

Can someone with permissions please help merge this (or grant me permissions to do so)?

Thanks!

@Flakebi
Flakebi merged commit 52af04d into GPUOpen-Drivers:dev Nov 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants