[Mlir-commits] [mlir] [mlir][LLVM] Add support for constant struct with multiple fields (PR #102752)
Tobias Gysi
llvmlistbot at llvm.org
Thu Aug 22 06:17:23 PDT 2024
================
@@ -2710,32 +2711,38 @@ 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";
+ ArrayRef<Type> elementTypes = structType.getBody();
+ if (arrayAttr.size() != elementTypes.size()) {
+ return emitOpError() << "expected array attribute of size "
+ << elementTypes.size();
}
- 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";
+ for (auto elementTy : elementTypes) {
+ if (!isa<IntegerType, FloatType, LLVMPPCFP128Type>(elementTy)) {
+ return emitOpError() << "expected struct element types to be floating "
+ "point type or integer type";
+ }
}
- 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) {
+ Attribute element = arrayAttr[i];
+ if (!isa<IntegerAttr, FloatAttr>(element)) {
+ return emitOpError()
+ << "expected struct element attribute types to be floating "
+ "point type or integer type";
+ }
+ auto elementType = cast<TypedAttr>(element).getType();
----------------
gysit wrote:
Ok I will land it then.
https://github.com/llvm/llvm-project/pull/102752
More information about the Mlir-commits
mailing list