@@ -305,26 +305,8 @@ combineOneSpec(DataLayoutSpecInterface spec,
305305 DenseMap<StringAttr, DataLayoutEntryInterface> newEntriesForID;
306306 spec.bucketEntriesByType (newEntriesForType, newEntriesForID);
307307
308- // Try overwriting the old entries with the new ones.
309- for (auto &kvp : newEntriesForType) {
310- if (!entriesForType.count (kvp.first )) {
311- entriesForType[kvp.first ] = std::move (kvp.second );
312- continue ;
313- }
314-
315- Type typeSample = cast<Type>(kvp.second .front ().getKey ());
316- assert (&typeSample.getDialect () !=
317- typeSample.getContext ()->getLoadedDialect <BuiltinDialect>() &&
318- " unexpected data layout entry for built-in type" );
319-
320- auto interface = cast<DataLayoutTypeInterface>(typeSample);
321- if (!interface.areCompatible (entriesForType.lookup (kvp.first ), kvp.second ,
322- spec))
323- return failure ();
324-
325- overwriteDuplicateEntries (entriesForType[kvp.first ], kvp.second );
326- }
327-
308+ // Combine non-Type DL entries first so they are visible to the
309+ // `type.areCompatible` method, allowing to query global properties.
328310 for (const auto &kvp : newEntriesForID) {
329311 StringAttr id = cast<StringAttr>(kvp.second .getKey ());
330312 Dialect *dialect = id.getReferencedDialect ();
@@ -333,7 +315,7 @@ combineOneSpec(DataLayoutSpecInterface spec,
333315 continue ;
334316 }
335317
336- // Attempt to combine the enties using the dialect interface. If the
318+ // Attempt to combine the entries using the dialect interface. If the
337319 // dialect is not loaded for some reason, use the default combinator
338320 // that conservatively accepts identical entries only.
339321 entriesForID[id] =
@@ -345,6 +327,26 @@ combineOneSpec(DataLayoutSpecInterface spec,
345327 return failure ();
346328 }
347329
330+ // Try overwriting the old entries with the new ones.
331+ for (auto &kvp : newEntriesForType) {
332+ if (!entriesForType.count (kvp.first )) {
333+ entriesForType[kvp.first ] = std::move (kvp.second );
334+ continue ;
335+ }
336+
337+ Type typeSample = cast<Type>(kvp.second .front ().getKey ());
338+ assert (&typeSample.getDialect () !=
339+ typeSample.getContext ()->getLoadedDialect <BuiltinDialect>() &&
340+ " unexpected data layout entry for built-in type" );
341+
342+ auto interface = cast<DataLayoutTypeInterface>(typeSample);
343+ if (!interface.areCompatible (entriesForType.lookup (kvp.first ), kvp.second ,
344+ spec, entriesForID))
345+ return failure ();
346+
347+ overwriteDuplicateEntries (entriesForType[kvp.first ], kvp.second );
348+ }
349+
348350 return success ();
349351}
350352
0 commit comments