Skip to content

Add support for visiting op classes#140

Merged
Flakebi merged 2 commits into
GPUOpen-Drivers:devfrom
jasilvanus:jsilvanu/opclass
May 6, 2026
Merged

Add support for visiting op classes#140
Flakebi merged 2 commits into
GPUOpen-Drivers:devfrom
jasilvanus:jsilvanu/opclass

Conversation

@jasilvanus
Copy link
Copy Markdown
Contributor

Op classes are sets of ops, providing a common base class in the op class hierarchy,
which can be used to group sets of ops with a common property.

Before this patch, op class only support isa<> checks, but not visiting.

This was because visiting relies on OpDescription::get<OpT>, which is only supported
for concrete ops, but not op classes.

This patch changes that by introducing a new OpDescription::getAll<OpT> template
which returns an ArrayRef of OpDescriptions. The existing get<OpT> template
is implemented in terms of the new getAll template.

Visitor code is changed to use getAll instead, and handle non-trivial array refs
(representing op classes) accordingly, using the already existing mechanism for op sets.

I wondered whether it would be better to remove the existing get method and migrate everything to the new getAll method (and renaming it back to get). However, that would require to add support for op classes in all places that rely on OpDescriptions and get, which is more than just visitors. Thus I chose to add a new method for this.

Also, we could instead provide a generic implementation of get in terms of getAll, because all implementations of get are the same: They return getAll()[0]. However, that would also add such methods for op classes, which we don't want. We could assert that the length is one, but that turns a link-time error into a debug-only assertion failure, which is strictly worse. Maybe we could add some more traits that allow to detect op classes, but I didn't want to complicate things further.

Comment thread test/unit/interface/VisitorIRTests.cpp Outdated
Comment thread include/llvm-dialects/Dialect/OpDescription.h Outdated
Comment thread lib/Dialect/OpDescription.cpp Outdated
@Flakebi
Copy link
Copy Markdown
Member

Flakebi commented May 6, 2026

Thanks, the comment reads good now.

There is an ArrayRef constructor that takes a single element: https://llvm.org/doxygen/classllvm_1_1ArrayRef.html#a7297c362c4fd96749704f50f1212b823

And a couple more std::array<*, 1> in the code

@jasilvanus jasilvanus force-pushed the jsilvanu/opclass branch 3 times, most recently from 02489fe to b8c066b Compare May 6, 2026 18:12
Op classes are sets of ops, providing a common base class in the op class hierarchy,
which can be used to group sets of ops with a common property.

Before this patch, op class only support `isa<>` checks, but not visiting.

This was because visiting relies on `OpDescription::get<OpT>`, which is only supported
for concrete ops, but not op classes.

This patch changes that by introducing a new `OpDescription::getAll<OpT>` template
which returns an `ArrayRef` of OpDescriptions. The existing `get<OpT>` template
is implemented in terms of the new `getAll` template.

Visitor code is changed to use `getAll` instead, and handle non-trivial array refs
(representing op classes) accordingly, using the already existing mechanism for op sets.
Copy link
Copy Markdown
Member

@Flakebi Flakebi left a comment

Choose a reason for hiding this comment

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

Thanks, that’s a nice diff!

@Flakebi Flakebi merged commit 9771937 into GPUOpen-Drivers:dev May 6, 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