diff --git a/mlir/include/mlir/IR/AsmState.h b/mlir/include/mlir/IR/AsmState.h --- a/mlir/include/mlir/IR/AsmState.h +++ b/mlir/include/mlir/IR/AsmState.h @@ -211,15 +211,15 @@ /// Create a new unmanaged resource directly referencing the provided data. /// `dataIsMutable` indicates if the allocated data can be mutated. By /// default, we treat unmanaged blobs as immutable. - static AsmResourceBlob allocate(ArrayRef data, size_t align, - bool dataIsMutable = false) { + static AsmResourceBlob allocateWithAlign(ArrayRef data, size_t align, + bool dataIsMutable = false) { return AsmResourceBlob(data, align, /*deleter=*/{}, /*dataIsMutable=*/false); } template - static std::enable_if_t::value, AsmResourceBlob> - allocate(ArrayRef data, bool dataIsMutable = false) { - return allocate( + static AsmResourceBlob allocateInferAlign(ArrayRef data, + bool dataIsMutable = false) { + return allocateWithAlign( ArrayRef((const char *)data.data(), data.size() * sizeof(T)), alignof(T)); } diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -219,8 +219,8 @@ static void checkNativeAccess(MLIRContext *ctx, ArrayRef data, Type elementType) { auto type = RankedTensorType::get(data.size(), elementType); - auto attr = - AttrT::get(type, "resource", UnmanagedAsmResourceBlob::allocate(data)); + auto attr = AttrT::get(type, "resource", + UnmanagedAsmResourceBlob::allocateInferAlign(data)); // Check that we can access and iterate the data properly. Optional> attrData = attr.tryGetAsArrayRef(); @@ -279,7 +279,7 @@ ArrayRef data; auto type = RankedTensorType::get(data.size(), builder.getI32Type()); Attribute i32ResourceAttr = DenseI32ResourceElementsAttr::get( - type, "resource", UnmanagedAsmResourceBlob::allocate(data)); + type, "resource", UnmanagedAsmResourceBlob::allocateInferAlign(data)); EXPECT_TRUE(i32ResourceAttr.isa()); EXPECT_FALSE(i32ResourceAttr.isa()); @@ -296,7 +296,8 @@ EXPECT_DEBUG_DEATH( { DenseBoolResourceElementsAttr::get( - type, "resource", UnmanagedAsmResourceBlob::allocate(data)); + type, "resource", + UnmanagedAsmResourceBlob::allocateInferAlign(data)); }, "alignment mismatch between expected alignment and blob alignment"); } @@ -311,7 +312,8 @@ EXPECT_DEBUG_DEATH( { DenseBoolResourceElementsAttr::get( - type, "resource", UnmanagedAsmResourceBlob::allocate(data)); + type, "resource", + UnmanagedAsmResourceBlob::allocateInferAlign(data)); }, "invalid shape element type for provided type `T`"); }