[Mlir-commits] [mlir] [mlir][LLVMIR] Check number of elements in `mlir.constant` verifier (PR #102906)
Tobias Gysi
llvmlistbot at llvm.org
Mon Aug 12 09:29:06 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;
----------------
gysit wrote:
`getVectorNumElements` maybe helpful (https://github.com/llvm/llvm-project/blob/7c4c72b52038810a8997938a2b3485363cd6be3a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp#L899).
https://github.com/llvm/llvm-project/pull/102906
More information about the Mlir-commits
mailing list