[Mlir-commits] [mlir] [mlir] Method to iterate over registered operations for a given dialect class. (PR #112344)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 16 12:21:11 PDT 2024
================
@@ -711,6 +714,20 @@ ArrayRef<RegisteredOperationName> MLIRContext::getRegisteredOperations() {
return impl->sortedRegisteredOperations;
}
+/// Return information for registered operations by dialect.
+ArrayRef<RegisteredOperationName>
+MLIRContext::getRegisteredOperationsByDialect(StringRef dialectName) {
+ auto lowerBound =
+ std::lower_bound(impl->sortedRegisteredOperations.begin(),
+ impl->sortedRegisteredOperations.end(), dialectName,
+ [](auto &lhs, auto &rhs) {
+ return lhs.getDialect().getNamespace().compare(
+ rhs.getDialect().getNamespace());
+ });
+ return ArrayRef(impl->sortedRegisteredOperations.data(),
+ impl->operationCount);
----------------
graphite-app[bot] wrote:
The current implementation doesn't filter operations by dialect as intended. To achieve the desired functionality, replace these lines with:
```cpp
size_t count = std::distance(lowerBound, impl->sortedRegisteredOperations.end());
return ArrayRef(lowerBound, count);
```
This modification will ensure that only the operations for the specified dialect are returned. The `lowerBound` iterator marks the start of the operations for the given dialect, and `count` represents the number of operations belonging to that dialect.
*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
https://github.com/llvm/llvm-project/pull/112344
More information about the Mlir-commits
mailing list