[fir] Add !fir.len type conversion
authorValentin Clement <clementval@gmail.com>
Mon, 15 Nov 2021 09:17:50 +0000 (10:17 +0100)
committerValentin Clement <clementval@gmail.com>
Mon, 15 Nov 2021 09:18:23 +0000 (10:18 +0100)
This patch adds the !fir.len type conversion. The type is converted
to the a 32 bits integer.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Reviewed By: kiranchandramohan

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

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

index ec0607f..ba10280 100644 (file)
@@ -73,6 +73,11 @@ public:
       // Convert to i32 because of LLVM GEP indexing restriction.
       return mlir::IntegerType::get(field.getContext(), 32);
     });
+    addConversion([&](fir::LenType field) {
+      // Get size of len paramter from the descriptor.
+      return getModel<Fortran::runtime::typeInfo::TypeParameterValue>()(
+          &getContext());
+    });
     addConversion(
         [&](fir::ComplexType cmplx) { return convertComplexType(cmplx); });
     addConversion(
index 5ab21a4..d1e93a4 100644 (file)
@@ -293,3 +293,11 @@ func private @foo1(%arg0: !fir.boxchar<2>)
 func private @foo0(%arg0: !fir.field)
 // CHECK-LABEL: foo0
 // CHECK-SAME: i32
+
+// -----
+
+// Test `!fir.len` conversion.
+
+func private @foo0(%arg0: !fir.len)
+// CHECK-LABEL: foo0
+// CHECK-SAME: i64