[Mlir-commits] [mlir] 18778b8 - [mlir] Fix merging of delayed registrations during DialectRegistry::appendTo

Matthias Springer llvmlistbot at llvm.org
Wed Jan 26 00:29:01 PST 2022


Author: Matthias Springer
Date: 2022-01-26T17:28:42+09:00
New Revision: 18778b8863522e3043a0134eb31cd60127bd962b

URL: https://github.com/llvm/llvm-project/commit/18778b8863522e3043a0134eb31cd60127bd962b
DIFF: https://github.com/llvm/llvm-project/commit/18778b8863522e3043a0134eb31cd60127bd962b.diff

LOG: [mlir] Fix merging of delayed registrations during DialectRegistry::appendTo

The existing implementation called DenseMap::insert, which is a no-op if the map already contains an entry with the same key.

Differential Revision: https://reviews.llvm.org/D118165

Added: 
    

Modified: 
    mlir/include/mlir/IR/Dialect.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h
index 0ee8057d1e666..7fb298c1b9425 100644
--- a/mlir/include/mlir/IR/Dialect.h
+++ b/mlir/include/mlir/IR/Dialect.h
@@ -331,7 +331,22 @@ class DialectRegistry {
       destination.insert(nameAndRegistrationIt.second.first,
                          nameAndRegistrationIt.first,
                          nameAndRegistrationIt.second.second);
-    destination.interfaces.insert(interfaces.begin(), interfaces.end());
+    // Merge interfaces.
+    for (auto it : interfaces) {
+      TypeID dialect = it.first;
+      auto destInterfaces = destination.interfaces.find(dialect);
+      if (destInterfaces == destination.interfaces.end()) {
+        destination.interfaces[dialect] = it.second;
+        continue;
+      }
+      // The destination already has delayed interface registrations for this
+      // dialect. Merge registrations into the destination registry.
+      destInterfaces->second.dialectInterfaces.append(
+          it.second.dialectInterfaces.begin(),
+          it.second.dialectInterfaces.end());
+      destInterfaces->second.objectInterfaces.append(
+          it.second.objectInterfaces.begin(), it.second.objectInterfaces.end());
+    }
   }
 
   /// Return the names of dialects known to this registry.


        


More information about the Mlir-commits mailing list