[Mlir-commits] [mlir] [mlir][llvm dialect] Verify element type of nested types (PR #148975)
James Newling
llvmlistbot at llvm.org
Wed Jul 16 10:16:38 PDT 2025
================
@@ -3112,6 +3113,18 @@ static int64_t getNumElements(Type t) {
return 1;
}
+/// Determine the element type of `type`. Supported types are `VectorType`,
+/// `TensorType`, and `LLVMArrayType`. Everything else is treated as a scalar.
+static Type getElementType(Type type) {
+ while (auto arrayType = dyn_cast<LLVM::LLVMArrayType>(type))
+ type = arrayType.getElementType();
+ if (auto vecType = dyn_cast<VectorType>(type))
+ return vecType.getElementType();
+ if (auto tenType = dyn_cast<TensorType>(type))
----------------
newling wrote:
Should the following fail to verify?
```
%0 = llvm.mlir.constant(dense<[1.0, 1.0]> : tensor<2xf64>) : vector<2xf64>
```
It currently roundtrips without issue.
Maybe what is confusing here is that I'm using this method to test both the attribute's element type as well the constant op's result's element type?
https://github.com/llvm/llvm-project/pull/148975
More information about the Mlir-commits
mailing list