[Mlir-commits] [mlir] [mlir][LLVMIR] Check number of elements in `mlir.constant` verifier (PR #102906)
Matthias Springer
llvmlistbot at llvm.org
Tue Aug 13 01:14:01 PDT 2024
================
@@ -2666,6 +2666,20 @@ OpFoldResult LLVM::ZeroOp::fold(FoldAdaptor) {
// ConstantOp.
//===----------------------------------------------------------------------===//
+/// Compute the total number of elements in the given type, also taking into
+/// account nested types. Supported types are `VectorType`, `LLVMArrayType` and
+/// `LLVMFixedVectorType`. Everything else is treated as a scalar.
+static int64_t getNumElements(Type t) {
+ if (auto vecType = dyn_cast<VectorType>(t))
+ return vecType.getNumElements() * getNumElements(vecType.getElementType());
+ if (auto arrayType = dyn_cast<LLVM::LLVMArrayType>(t))
+ return arrayType.getNumElements() *
+ getNumElements(arrayType.getElementType());
+ if (auto vecType = dyn_cast<LLVMFixedVectorType>(t))
+ return vecType.getNumElements() * getNumElements(vecType.getElementType());
+ return 1;
----------------
matthias-springer wrote:
This does not take into account nested vectors unfortunately.
https://github.com/llvm/llvm-project/pull/102906
More information about the Mlir-commits
mailing list