[Mlir-commits] [mlir] [mlir][LLVM] Add support for constant struct with multiple fields (PR #102752)

Tobias Gysi llvmlistbot at llvm.org
Tue Aug 20 11:32:42 PDT 2024


================
@@ -557,20 +557,20 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
     return llvm::UndefValue::get(llvmType);
   if (auto *structType = dyn_cast<::llvm::StructType>(llvmType)) {
     auto arrayAttr = dyn_cast<ArrayAttr>(attr);
-    if (!arrayAttr || arrayAttr.size() != 2) {
-      emitError(loc, "expected struct type to be a complex number");
+    if (!arrayAttr) {
+      emitError(loc, "expected an array attribute for a struct constant");
       return nullptr;
     }
-    llvm::Type *elementType = structType->getElementType(0);
-    llvm::Constant *real =
-        getLLVMConstant(elementType, arrayAttr[0], loc, moduleTranslation);
-    if (!real)
-      return nullptr;
-    llvm::Constant *imag =
-        getLLVMConstant(elementType, arrayAttr[1], loc, moduleTranslation);
-    if (!imag)
-      return nullptr;
-    return llvm::ConstantStruct::get(structType, {real, imag});
+    SmallVector<llvm::Constant *, 8> structElements;
+    structElements.reserve(structType->getNumElements());
+    for (size_t i = 0; i < arrayAttr.size(); ++i) {
----------------
gysit wrote:

```suggestion
    for (auto [elemType, elemAttr] : zip_equal(arrayAttr, structType.getElementTypes()))
```
nit: Would it be possible to use zip_equal here? 

https://github.com/llvm/llvm-project/pull/102752


More information about the Mlir-commits mailing list