[flang] Add type conversion for !fir.box<none>
authorValentin Clement <clementval@gmail.com>
Wed, 9 Feb 2022 14:11:55 +0000 (15:11 +0100)
committerValentin Clement <clementval@gmail.com>
Wed, 9 Feb 2022 14:13:47 +0000 (15:13 +0100)
`none` is used in `fir.box` type to specify a polymorphic type.
This patch add the conversion from `!fir.box<none>` to LLVM.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D119325

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
flang/lib/Optimizer/CodeGen/TypeConverter.h
flang/test/Fir/types-to-llvm.fir

index 10a30bf..3202b00 100644 (file)
@@ -124,6 +124,10 @@ public:
       return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
                                                     /*isPacked=*/false);
     });
+    addConversion([&](mlir::NoneType none) {
+      return mlir::LLVM::LLVMStructType::getLiteral(
+          none.getContext(), llvm::None, /*isPacked=*/false);
+    });
   }
 
   // i32 is used here because LLVM wants i32 constants when indexing into struct
index f47410d..a8b1fd4 100644 (file)
@@ -418,3 +418,11 @@ func private @foo0(%arg0: tuple<i64, !fir.box<i32>>)
 func private @foo1(%arg0: !fir.type<derived8{a:i64,b:!fir.box<i32>}>)
 // CHECK-LABEL: foo1
 // CHECK-SAME: !llvm.struct<"derived8", (i64, struct<(ptr<i32>, i{{.*}})>)>
+
+// -----
+
+// Test fir.box<none> translation.
+// `none` is used for polymorphic type.
+func private @foo0(%arg0: !fir.box<none>)
+// CHECK-LABEL: foo0
+// CHECK-SAME: !llvm.ptr<struct<(ptr<struct<()>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>)