[llvm-branch-commits] [mlir] 45c9ce8 - Revert "[mlir][python] allow DenseIntElementsAttr for index type (#118947)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 28 09:34:41 PST 2025


Author: Matthias Gehre
Date: 2025-01-28T18:34:38+01:00
New Revision: 45c9ce83e7b91efc06f94cdf20fe9439e46e769e

URL: https://github.com/llvm/llvm-project/commit/45c9ce83e7b91efc06f94cdf20fe9439e46e769e
DIFF: https://github.com/llvm/llvm-project/commit/45c9ce83e7b91efc06f94cdf20fe9439e46e769e.diff

LOG: Revert "[mlir][python] allow DenseIntElementsAttr for index type (#118947)"

This reverts commit 9dd762e8b10586e749b0ddf3542e5dccf8392395.

Added: 
    

Modified: 
    mlir/include/mlir-c/BuiltinAttributes.h
    mlir/lib/Bindings/Python/IRAttributes.cpp
    mlir/lib/CAPI/IR/BuiltinAttributes.cpp
    mlir/test/python/dialects/builtin.py
    mlir/test/python/ir/array_attributes.py
    mlir/test/python/ir/attributes.py

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/BuiltinAttributes.h b/mlir/include/mlir-c/BuiltinAttributes.h
index 1d0edf9ea809d2..7c8c84e55b962f 100644
--- a/mlir/include/mlir-c/BuiltinAttributes.h
+++ b/mlir/include/mlir-c/BuiltinAttributes.h
@@ -556,8 +556,6 @@ MLIR_CAPI_EXPORTED int64_t
 mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos);
 MLIR_CAPI_EXPORTED uint64_t
 mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos);
-MLIR_CAPI_EXPORTED uint64_t
-mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos);
 MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr,
                                                             intptr_t pos);
 MLIR_CAPI_EXPORTED double

diff  --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index dcd098c20d389a..7bc21a31c3c84c 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -1372,19 +1372,13 @@ class PyDenseIntElementsAttribute
 
     MlirType type = mlirAttributeGetType(*this);
     type = mlirShapedTypeGetElementType(type);
-    // Index type can also appear as a DenseIntElementsAttr and therefore can be
-    // casted to integer.
-    assert(mlirTypeIsAInteger(type) ||
-           mlirTypeIsAIndex(type) && "expected integer/index element type in "
-                                     "dense int elements attribute");
+    assert(mlirTypeIsAInteger(type) &&
+           "expected integer element type in dense int elements attribute");
     // Dispatch element extraction to an appropriate C function based on the
     // elemental type of the attribute. nb::int_ is implicitly constructible
     // from any C++ integral type and handles bitwidth correctly.
     // TODO: consider caching the type properties in the constructor to avoid
     // querying them on each element access.
-    if (mlirTypeIsAIndex(type)) {
-      return mlirDenseElementsAttrGetIndexValue(*this, pos);
-    }
     unsigned width = mlirIntegerTypeGetWidth(type);
     bool isUnsigned = mlirIntegerTypeIsUnsigned(type);
     if (isUnsigned) {

diff  --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
index 8d57ab6b59e79c..11d1ade552f5a2 100644
--- a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
@@ -758,9 +758,6 @@ int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos) {
 uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos) {
   return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
 }
-uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos) {
-  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
-}
 float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos) {
   return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<float>()[pos];
 }

diff  --git a/mlir/test/python/dialects/builtin.py b/mlir/test/python/dialects/builtin.py
index 973a0eaeca2cdb..18ebba61e7fea8 100644
--- a/mlir/test/python/dialects/builtin.py
+++ b/mlir/test/python/dialects/builtin.py
@@ -246,7 +246,3 @@ def testDenseElementsAttr():
         # CHECK{LITERAL}: dense<[[0, 1], [2, 3]]> : tensor<2x2xi32>
         print(DenseElementsAttr.get(values, type=VectorType.get((2, 2), i32)))
         # CHECK{LITERAL}: dense<[[0, 1], [2, 3]]> : vector<2x2xi32>
-        idx_values = np.arange(4, dtype=np.int64)
-        idx_type = IndexType.get()
-        print(DenseElementsAttr.get(idx_values, type=VectorType.get([4], idx_type)))
-        # CHECK{LITERAL}: dense<[0, 1, 2, 3]> : vector<4xindex>

diff  --git a/mlir/test/python/ir/array_attributes.py b/mlir/test/python/ir/array_attributes.py
index ef1d835fc64012..256a69a939658d 100644
--- a/mlir/test/python/ir/array_attributes.py
+++ b/mlir/test/python/ir/array_attributes.py
@@ -572,10 +572,6 @@ def testGetDenseElementsIndex():
         print(arr)
         # CHECK: True
         print(arr.dtype == np.int64)
-        array = np.array([1, 2, 3], dtype=np.int64)
-        attr = DenseIntElementsAttr.get(array, type=VectorType.get([3], idx_type))
-        # CHECK: [1, 2, 3]
-        print(list(DenseIntElementsAttr(attr)))
 
 
 # CHECK-LABEL: TEST: testGetDenseResourceElementsAttr

diff  --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py
index 2f3c4460d3f590..00c3e1b4decdb7 100644
--- a/mlir/test/python/ir/attributes.py
+++ b/mlir/test/python/ir/attributes.py
@@ -366,10 +366,6 @@ def testDenseIntAttr():
         # CHECK: i1
         print(ShapedType(a.type).element_type)
 
-        shape = Attribute.parse("dense<[0, 1, 2, 3]> : vector<4xindex>")
-        # CHECK: attr: dense<[0, 1, 2, 3]>
-        print("attr:", shape)
-
 
 @run
 def testDenseArrayGetItem():


        


More information about the llvm-branch-commits mailing list