[flang-commits] [flang] fd0417a - [flang] Add type conversion for !fir.box<none>

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Feb 9 06:13:57 PST 2022


Author: Valentin Clement
Date: 2022-02-09T15:13:47+01:00
New Revision: fd0417a3cf7d4cdee7d6984752453ce3ec93e860

URL: https://github.com/llvm/llvm-project/commit/fd0417a3cf7d4cdee7d6984752453ce3ec93e860
DIFF: https://github.com/llvm/llvm-project/commit/fd0417a3cf7d4cdee7d6984752453ce3ec93e860.diff

LOG: [flang] Add type conversion for !fir.box<none>

`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 at nvidia.com>
Co-authored-by: Jean Perier <jperier at nvidia.com>

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/TypeConverter.h
    flang/test/Fir/types-to-llvm.fir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index 10a30bfd86a2..3202b00e72c5 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -124,6 +124,10 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
       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

diff  --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir
index f47410dd4cc5..a8b1fd4225c7 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -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{{.*}})>>)


        


More information about the flang-commits mailing list