[flang-commits] [flang] 6c8eecd - [fir] Add !fir.len type conversion

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Nov 15 01:18:28 PST 2021


Author: Valentin Clement
Date: 2021-11-15T10:18:23+01:00
New Revision: 6c8eecd6769db3f8ef42d368f6d959504330968a

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

LOG: [fir] Add !fir.len type conversion

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 at nvidia.com>

Reviewed By: kiranchandramohan

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

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 ec0607fd7381d..ba10280b33257 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -73,6 +73,11 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
       // 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(

diff  --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir
index 5ab21a408235a..d1e93a4fa1eeb 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -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


        


More information about the flang-commits mailing list