From 94b0f17f4d882dab3779c253d6ac0663336233c1 Mon Sep 17 00:00:00 2001 From: Jonas Rickert Date: Wed, 11 Jun 2025 18:03:44 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"Allow=20to=20use=20the=20DenseElement?= =?UTF-8?q?sAttr=20get=20methods=20to=20be=20used=20with=20types=20?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mlir/include/mlir/IR/BuiltinAttributes.h | 6 +++--- mlir/lib/IR/BuiltinAttributes.cpp | 16 +++++++--------- mlir/unittests/IR/AttributeTest.cpp | 22 ---------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h index 7624b5e761e9f..901df3a25a46f 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.h +++ b/mlir/include/mlir/IR/BuiltinAttributes.h @@ -112,9 +112,9 @@ class DenseElementsAttr : public Attribute { static DenseElementsAttr get(ShapedType type, ArrayRef values); /// Constructs a dense integer elements attribute from an array of integer - /// or floating-point values. Each value is expected to be the same as the - /// storage bitwidth of the element type of 'type'. 'type' must be a vector or - /// tensor with static shape. + /// or floating-point values. Each value is expected to be the same bitwidth + /// of the element type of 'type'. 'type' must be a vector or tensor with + /// static shape. template ::is_integer || is_valid_cpp_fp_type::value>> diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp index b90713e890889..112e3f376bd41 100644 --- a/mlir/lib/IR/BuiltinAttributes.cpp +++ b/mlir/lib/IR/BuiltinAttributes.cpp @@ -1104,15 +1104,13 @@ bool DenseElementsAttr::isValidRawBuffer(ShapedType type, /// invariants that the templatized 'getValues' method cannot. static bool isValidIntOrFloat(Type type, int64_t dataEltSize, bool isInt, bool isSigned) { - // Make sure that the data element size is the same as the type element - // storage width. - const size_t denseEltStorageBitWidth = getDenseElementStorageWidth(type); - const size_t dataSizeBitWidth = static_cast(dataEltSize * CHAR_BIT); - if (denseEltStorageBitWidth != dataSizeBitWidth) { - LLVM_DEBUG(llvm::dbgs() - << "expected dense element bit width " << denseEltStorageBitWidth - << " to match data size " << dataSizeBitWidth << " for type " - << type << "\n"); + // Make sure that the data element size is the same as the type element width. + auto denseEltBitWidth = getDenseElementBitWidth(type); + auto dataSize = static_cast(dataEltSize * CHAR_BIT); + if (denseEltBitWidth != dataSize) { + LLVM_DEBUG(llvm::dbgs() << "expected dense element bit width " + << denseEltBitWidth << " to match data size " + << dataSize << " for type " << type << "\n"); return false; } diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp index 03c08ed22a77f..9203248a83baf 100644 --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -570,26 +570,4 @@ TEST(NonSplattedDenseElementAttrTest, GetNonSplatRawDataI16) { .getNonSplatRawData(), expected); } - -TEST(NonSplattedDenseElementAttrTest, GetFromRawI7) { - constexpr std::size_t numberOfElements = 6; - static constexpr std::array rawValues = {1, 2, 3, - 4, 5, 6}; - - mlir::MLIRContext context; - mlir::OpBuilder b(&context); - - auto values = mlir::DenseElementsAttr::get( - mlir::RankedTensorType::get({numberOfElements}, b.getIntegerType(7)), - ArrayRef(rawValues)); - auto fromRaw = mlir::DenseIntOrFPElementsAttr::getFromRawBuffer( - values.getType(), values.getRawData()); - - EXPECT_EQ(values, fromRaw); - EXPECT_EQ(fromRaw.getElementType(), b.getIntegerType(7)); - EXPECT_EQ(fromRaw.getNumElements(), numberOfElements); - for (auto [fr, e] : llvm::zip_equal(fromRaw.getValues(), rawValues)) { - EXPECT_EQ(fr, e); - } -} } // namespace