[Mlir-commits] [mlir] [mlir][LLVM] Add support for constant struct with multiple fields (PR #102752)
Sirui Mu
llvmlistbot at llvm.org
Wed Aug 21 09:06:44 PDT 2024
================
@@ -2710,32 +2710,31 @@ LogicalResult LLVM::ConstantOp::verify() {
}
return success();
}
- if (auto structType = llvm::dyn_cast<LLVMStructType>(getType())) {
- if (structType.getBody().size() != 2 ||
- structType.getBody()[0] != structType.getBody()[1]) {
- return emitError() << "expected struct type with two elements of the "
- "same type, the type of a complex constant";
+ if (auto structType = dyn_cast<LLVMStructType>(getType())) {
+ auto arrayAttr = dyn_cast<ArrayAttr>(getValue());
+ if (!arrayAttr) {
+ return emitOpError() << "expected array attribute for a struct constant";
}
- auto arrayAttr = llvm::dyn_cast<ArrayAttr>(getValue());
- if (!arrayAttr || arrayAttr.size() != 2) {
- return emitOpError() << "expected array attribute with two elements, "
- "representing a complex constant";
- }
- auto re = llvm::dyn_cast<TypedAttr>(arrayAttr[0]);
- auto im = llvm::dyn_cast<TypedAttr>(arrayAttr[1]);
- if (!re || !im || re.getType() != im.getType()) {
- return emitOpError()
- << "expected array attribute with two elements of the same type";
+ ArrayRef<Type> elementTypes = structType.getBody();
+ if (arrayAttr.size() != elementTypes.size()) {
+ return emitOpError() << "expected array attribute of size "
+ << elementTypes.size();
}
- Type elementType = structType.getBody()[0];
- if (!llvm::isa<IntegerType, Float16Type, Float32Type, Float64Type>(
- elementType)) {
- return emitError()
- << "expected struct element types to be floating point type or "
- "integer type";
+ for (size_t i = 0; i < elementTypes.size(); ++i) {
+ auto element = arrayAttr[i];
+ if (!isa<IntegerAttr, FloatAttr>(element)) {
+ return emitOpError() << "expected struct element types to be floating "
----------------
Lancern wrote:
Test added.
https://github.com/llvm/llvm-project/pull/102752
More information about the Mlir-commits
mailing list