[flang-commits] [flang] 964536c - [fir] !fir.tdesc type conversion

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Nov 17 04:31:24 PST 2021


Author: Valentin Clement
Date: 2021-11-17T13:31:14+01:00
New Revision: 964536cf04e29ebc125cdb44484e2c2cd8e0bd9b

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

LOG: [fir] !fir.tdesc type conversion

Add !fir.tdesc type conversion.
!fir.tdesc is converted to a llvm.ptr<i8>.

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

Reviewed By: kiranchandramohan

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

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 87b47f749d04..0f112c630d8f 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -90,6 +90,9 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
     addConversion([&](fir::SequenceType sequence) {
       return convertSequenceType(sequence);
     });
+    addConversion([&](fir::TypeDescType tdesc) {
+      return convertTypeDescType(tdesc.getContext());
+    });
     addConversion([&](fir::VectorType vecTy) {
       return mlir::VectorType::get(llvm::ArrayRef<int64_t>(vecTy.getLen()),
                                    convertType(vecTy.getEleTy()));
@@ -283,6 +286,14 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
     return mlir::LLVM::LLVMPointerType::get(baseTy);
   }
 
+  // fir.tdesc<any>  -->  llvm<"i8*">
+  // TODO: For now use a void*, however pointer identity is not sufficient for
+  // the f18 object v. class distinction (F2003).
+  mlir::Type convertTypeDescType(mlir::MLIRContext *ctx) {
+    return mlir::LLVM::LLVMPointerType::get(
+        mlir::IntegerType::get(&getContext(), 8));
+  }
+
   /// Convert llvm::Type::TypeID to mlir::Type
   mlir::Type fromRealTypeID(llvm::Type::TypeID typeID, fir::KindTy kind) {
     switch (typeID) {

diff  --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir
index 4eed1ca2dfdc..6c3223572963 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -321,3 +321,23 @@ func private @foo0(%arg0: !fir.field)
 func private @foo0(%arg0: !fir.len)
 // CHECK-LABEL: foo0
 // CHECK-SAME: i64
+
+// -----
+
+// Test `!fir.tdesc` conversion.
+
+func private @foo0(%arg0: !fir.tdesc<!fir.type<x>>)
+// CHECK-LABEL: foo0
+// CHECK-SAME:  !llvm.ptr<i8>
+
+func private @foo1(%arg : !fir.tdesc<!fir.array<100xf32>>)
+// CHECK-LABEL: foo1
+// CHECK-SAME:  !llvm.ptr<i8>
+
+func private @foo2(%arg : !fir.tdesc<f32>)
+// CHECK-LABEL: foo2
+// CHECK-SAME:  !llvm.ptr<i8>
+
+func private @foo3(%arg : !fir.tdesc<!fir.type<derived7{f1:f32,f2:f32}>>)
+// CHECK-LABEL: foo3
+// CHECK-SAME:  !llvm.ptr<i8>


        


More information about the flang-commits mailing list