[flang-commits] [flang] [mlir] [mlir] Support DialectRegistry extension comparison (PR #101119)
Mehdi Amini via flang-commits
flang-commits at lists.llvm.org
Thu Aug 1 16:07:09 PDT 2024
================
@@ -173,6 +179,42 @@ bool dialect_extension_detail::hasPromisedInterface(Dialect &dialect,
// DialectRegistry
//===----------------------------------------------------------------------===//
+namespace {
+template <typename Fn>
+void applyExtensionsFn(
+ Fn &&applyExtension,
+ const llvm::MapVector<TypeID, std::unique_ptr<DialectExtensionBase>>
+ &extensions) {
+ // Note: Additional extensions may be added while applying an extension.
+ // The iterators will be invalidated if extensions are added so we'll keep
+ // a copy of the extensions for ourselves.
+
+ const auto extractExtension =
+ [](const auto &entry) -> DialectExtensionBase * {
+ return entry.second.get();
+ };
+
+ auto startIt = extensions.begin(), endIt = extensions.end();
+ size_t count = 0;
+ while (startIt != endIt) {
+ count += endIt - startIt;
+
+ // Grab the subset of extensions we'll apply in this iteration.
+ const auto subset =
+ llvm::map_to_vector(llvm::make_range(startIt, endIt), extractExtension);
+
+ // Apply!
+ for (const auto *ext : subset) {
+ applyExtension(*ext);
+ }
----------------
joker-eph wrote:
```suggestion
for (const auto *ext : subset)
applyExtension(*ext);
```
https://github.com/llvm/llvm-project/pull/101119
More information about the flang-commits
mailing list