[Mlir-commits] [mlir] [WIP][mlir] Make `DenseElementsAttr::reshape(...)` take a shape instead of a type (PR #149947)
James Newling
llvmlistbot at llvm.org
Tue Jul 22 10:47:03 PDT 2025
================
@@ -1241,8 +1241,10 @@ ArrayRef<StringRef> DenseElementsAttr::getRawStringData() const {
/// Return a new DenseElementsAttr that has the same data as the current
/// attribute, but has been reshaped to 'newType'. The new type must have the
/// same total number of elements as well as element type.
-DenseElementsAttr DenseElementsAttr::reshape(ShapedType newType) {
+DenseElementsAttr DenseElementsAttr::reshape(ArrayRef<int64_t> newShape) {
+
ShapedType curType = getType();
+ auto newType = curType.cloneWith(newShape, curType.getElementType());
----------------
newling wrote:
Hi @MengmSun -- I just tried your example above on this branch with `mlir-opt -convert-to-llvm --canonicalize test.mlir` and it gives
```mlir
llvm.func @canonicalize_extract_shapecast_different_element_type() -> !llvm.array<1 x vector<192xi8>> {
%0 = llvm.mlir.constant(dense<1.000000e+00> : vector<1x192xf8E4M3FN>) : !llvm.array<1 x vector<192xi8>>
llvm.return %0 : !llvm.array<1 x vector<192xi8>>
}
```
which I think is what we want
https://github.com/llvm/llvm-project/pull/149947
More information about the Mlir-commits
mailing list