[Mlir-commits] [mlir] [MLIR][LLVM][DLTI] Handle data layout token 'n32:64' (PR #141299)

Tobias Gysi llvmlistbot at llvm.org
Sun May 25 02:45:11 PDT 2025


================
@@ -251,6 +251,30 @@ LogicalResult DataLayoutImporter::tryToEmplaceFunctionPointerAlignmentEntry(
   return success();
 }
 
+LogicalResult
+DataLayoutImporter::tryToEmplaceLegalIntWidthsEntry(StringRef token) {
+  auto key =
+      StringAttr::get(context, DLTIDialect::kDataLayoutLegalIntWidthsKey);
+  if (keyEntries.count(key))
+    return success();
+
+  FailureOr<SmallVector<uint64_t>> intWidths = tryToParseIntList(token);
+  if (failed(intWidths) || intWidths->empty())
+    return failure();
+
+  OpBuilder builder(context);
+  SmallVector<Attribute> intWidthAttrs;
+  intWidthAttrs.reserve(intWidths->size());
+  llvm::for_each(*intWidths, [&](uint64_t width) {
+    intWidthAttrs.push_back(builder.getI32IntegerAttr(width));
+  });
+
+  keyEntries.try_emplace(
+      key, DataLayoutEntryAttr::get(
+               key, ArrayAttr::get(key.getContext(), intWidthAttrs)));
----------------
gysit wrote:

Using DenseI32ArrayAttr to store integer bit widths would be nice. That way we do not need to create attributes for the individual scalar values. Note that the builder can also directly create a dense I32 array using `builder.getDenseI32ArrayAttr({1, 2, 3}))`.

https://github.com/llvm/llvm-project/pull/141299


More information about the Mlir-commits mailing list