@@ -293,21 +293,8 @@ mlir::detail::getDefaultStackAlignment(DataLayoutEntryInterface entry) {
293
293
return value.getValue ().getZExtValue ();
294
294
}
295
295
296
- // Returns the max vector op width if specified in the given entry. If the entry
297
- // is empty (meaning the spec is missing), returns std::nullopt.
298
296
std::optional<int64_t >
299
- mlir::detail::getMaxVectorOpWidth (DataLayoutEntryInterface entry) {
300
- if (entry == DataLayoutEntryInterface ())
301
- return std::nullopt;
302
-
303
- auto value = cast<IntegerAttr>(entry.getValue ());
304
- return value.getValue ().getZExtValue ();
305
- }
306
-
307
- // Returns the L1 cache size if specified in the given entry. If the entry
308
- // is empty (meaning the spec is missing), returns std::nullopt.
309
- std::optional<int64_t >
310
- mlir::detail::getL1CacheSizeInBytes (DataLayoutEntryInterface entry) {
297
+ mlir::detail::getDevicePropertyValueAsInt (DataLayoutEntryInterface entry) {
311
298
if (entry == DataLayoutEntryInterface ())
312
299
return std::nullopt;
313
300
@@ -348,15 +335,12 @@ static DataLayoutSpecInterface getSpec(Operation *operation) {
348
335
349
336
static TargetSystemSpecInterface getTargetSystemSpec (Operation *operation) {
350
337
if (operation) {
351
- ModuleOp moduleOp;
352
- if (isa<ModuleOp>(operation)) {
353
- moduleOp = llvm::dyn_cast<ModuleOp>(operation);
354
- } else {
338
+ ModuleOp moduleOp = dyn_cast<ModuleOp>(operation);
339
+ if (!moduleOp)
355
340
moduleOp = operation->getParentOfType <ModuleOp>();
356
- }
357
341
return moduleOp.getTargetSystemSpec ();
358
- } else
359
- return TargetSystemSpecInterface ();
342
+ }
343
+ return TargetSystemSpecInterface ();
360
344
}
361
345
362
346
// / Populates `opsWithLayout` with the list of proper ancestors of `leaf` that
@@ -677,44 +661,24 @@ uint64_t mlir::DataLayout::getStackAlignment() const {
677
661
return *stackAlignment;
678
662
}
679
663
680
- std::optional<int64_t > mlir::DataLayout::getMaxVectorOpWidth (
681
- TargetSystemSpecInterface::DeviceID deviceID) const {
682
- checkValid ();
683
- DataLayoutEntryInterface entry;
684
- if (originalTargetSystemDesc) {
685
- if (auto device =
686
- originalTargetSystemDesc.getDeviceSpecForDeviceID (deviceID))
687
- entry =
688
- device->getSpecForIdentifier (device->getMaxVectorOpWidthIdentifier ());
689
- }
690
- // Currently I am not caching the results because we do not return
691
- // default values of these properties. Instead if the property is
692
- // missing, we return std::nullopt so that the users can resort to
693
- // the default value however they want.
694
- if (auto iface = dyn_cast_or_null<DataLayoutOpInterface>(scope))
695
- return iface.getMaxVectorOpWidth (entry);
696
- else
697
- return detail::getMaxVectorOpWidth (entry);
698
- }
699
-
700
- std::optional<int64_t > mlir::DataLayout::getL1CacheSizeInBytes (
701
- TargetSystemSpecInterface::DeviceID deviceID) const {
664
+ std::optional<int64_t > mlir::DataLayout::getDevicePropertyValueAsInt (
665
+ TargetSystemSpecInterface::DeviceID deviceID,
666
+ StringAttr propertyName) const {
702
667
checkValid ();
703
668
DataLayoutEntryInterface entry;
704
669
if (originalTargetSystemDesc) {
705
- if (auto device =
670
+ if (std::optional<TargetDeviceSpecInterface> device =
706
671
originalTargetSystemDesc.getDeviceSpecForDeviceID (deviceID))
707
- entry = device->getSpecForIdentifier (
708
- device->getL1CacheSizeInBytesIdentifier ());
672
+ entry = device->getSpecForIdentifier (propertyName);
709
673
}
710
674
// Currently I am not caching the results because we do not return
711
675
// default values of these properties. Instead if the property is
712
676
// missing, we return std::nullopt so that the users can resort to
713
677
// the default value however they want.
714
678
if (auto iface = dyn_cast_or_null<DataLayoutOpInterface>(scope))
715
- return iface.getL1CacheSizeInBytes (entry);
679
+ return iface.getDevicePropertyValueAsInt (entry);
716
680
else
717
- return detail::getL1CacheSizeInBytes (entry);
681
+ return detail::getDevicePropertyValueAsInt (entry);
718
682
}
719
683
720
684
// ===----------------------------------------------------------------------===//
@@ -824,47 +788,46 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
824
788
LogicalResult
825
789
mlir::detail::verifyTargetSystemSpec (TargetSystemSpecInterface spec,
826
790
Location loc) {
827
- DenseMap<StringAttr, DataLayoutEntryInterface> device_desc_keys ;
828
- DenseSet<TargetSystemSpecInterface::DeviceID> device_ids ;
791
+ DenseMap<StringAttr, DataLayoutEntryInterface> deviceDescKeys ;
792
+ DenseSet<TargetSystemSpecInterface::DeviceID> deviceIDs ;
829
793
for (const auto &entry : spec.getEntries ()) {
830
- TargetDeviceSpecInterface tdd_spec = entry.second ;
794
+ TargetDeviceSpecInterface targetDeviceSpec = entry.second ;
831
795
// First, verify individual target device desc specs.
832
- if (failed (tdd_spec .verifyEntry (loc)))
796
+ if (failed (targetDeviceSpec .verifyEntry (loc)))
833
797
return failure ();
834
798
835
799
// Check that device IDs are unique across all entries.
836
- TargetSystemSpecInterface::DeviceID device_id = entry.first ;
837
- if (!device_ids .insert (device_id ).second ) {
800
+ TargetSystemSpecInterface::DeviceID deviceID = entry.first ;
801
+ if (!deviceIDs .insert (deviceID ).second ) {
838
802
return failure ();
839
803
}
840
804
841
- // collect all the keys used by all the tdd_specs .
842
- for (DataLayoutEntryInterface entry : tdd_spec .getEntries ()) {
805
+ // collect all the keys used by all the target device specs .
806
+ for (DataLayoutEntryInterface entry : targetDeviceSpec .getEntries ()) {
843
807
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey ())) {
844
- // tdd_spec does not support Type as a key.
808
+ // targetDeviceSpec does not support Type as a key.
845
809
return failure ();
846
810
} else {
847
- device_desc_keys [entry.getKey ().get <StringAttr>()] = entry;
811
+ deviceDescKeys [entry.getKey ().get <StringAttr>()] = entry;
848
812
}
849
813
}
850
814
}
851
815
852
- for (const auto &kvp : device_desc_keys) {
853
- StringAttr identifier = kvp.second .getKey ().get <StringAttr>();
854
- Dialect *dialect = identifier.getReferencedDialect ();
816
+ for (const auto &[keyName, keyVal] : deviceDescKeys) {
817
+ Dialect *dialect = keyName.getReferencedDialect ();
855
818
856
819
// Ignore attributes that belong to an unknown dialect, the dialect may
857
820
// actually implement the relevant interface but we don't know about that.
858
821
if (!dialect)
859
- continue ;
822
+ return failure () ;
860
823
861
824
const auto *iface = dyn_cast<DataLayoutDialectInterface>(dialect);
862
825
if (!iface) {
863
826
return emitError (loc)
864
827
<< " the '" << dialect->getNamespace ()
865
828
<< " ' dialect does not support identifier data layout entries" ;
866
829
}
867
- if (failed (iface->verifyEntry (kvp. second , loc)))
830
+ if (failed (iface->verifyEntry (keyVal , loc)))
868
831
return failure ();
869
832
}
870
833
0 commit comments