[PATCH] D113670: [Flang] Add type conversion for FIR heap type

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 11 06:18:51 PST 2021


kiranchandramohan created this revision.
kiranchandramohan added reviewers: clementval, awarzynski, rovka, jeanPerier, schweitz, svedanayagam, AlexisPerry, pmccormick.
Herald added a subscriber: mehdi_amini.
Herald added a project: Flang.
kiranchandramohan requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Convert fir.heap type to its llvm equivalent type (llvm.ptr)

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

Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Co-authored-by: Jean Perier <jperier at nvidia.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113670

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


Index: flang/test/Fir/types-to-llvm.fir
===================================================================
--- flang/test/Fir/types-to-llvm.fir
+++ flang/test/Fir/types-to-llvm.fir
@@ -28,6 +28,9 @@
 func private @foo1(%arg0: !fir.ref<!fir.array<10xf32>>)
 // CHECK-LABEL: foo1
 // CHECK-SAME: !llvm.ptr<array<10 x f32>>
+func private @foo2(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.type<_QMs1Ta1{x:i32,y:f32}>>>>)
+// CHECK-LABEL: foo2
+// CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"_QMs1Ta1", (i32, f32)>>, i64, i32, i8, i8, i8, i8, ptr<i8>, array<1 x i64>)>>
 
 // -----
 
@@ -61,6 +64,10 @@
 // CHECK-LABEL: foo3
 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"derived", (f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
 
+func private @foo4(%arg0: !fir.box<!fir.heap<!fir.type<_QMs1Ta1{x:i32,y:f32}>>>)
+// CHECK-LABEL: foo4
+// CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"_QMs1Ta1", (i32, f32)>>, i64, i32, i8, i8, i8, i8, ptr<i8>, array<1 x i64>)>>
+
 // -----
 
 // Test char types `!fir.char<k, n>`
@@ -82,6 +89,45 @@
 
 // -----
 
+// Test `!fir.heap<>` conversion.
+func private @foo0(%arg0: !fir.heap<i32>)
+// CHECK-LABEL: foo0
+// CHECK-SAME: !llvm.ptr<i32>
+
+func private @foo1(%arg0: !fir.heap<!fir.array<4xf32>>)
+// CHECK-LABEL: foo1
+// CHECK-SAME: !llvm.ptr<array<4 x f32>>
+
+func private @foo2(%arg0: !fir.heap<!fir.array<?xf32>>)
+// CHECK-LABEL: foo2
+// CHECK-SAME: !llvm.ptr<f32>
+
+func private @foo3(%arg0: !fir.heap<!fir.char<1,10>>)
+// CHECK-LABEL: foo3
+// CHECK-SAME: !llvm.ptr<array<10 x i8>>
+
+func private @foo4(%arg0: !fir.heap<!fir.char<1,?>>)
+// CHECK-LABEL: foo4
+// CHECK-SAME: !llvm.ptr<i8>
+
+func private @foo5(%arg0: !fir.heap<!fir.array<2xf32>>)
+// CHECK-LABEL: foo5
+// CHECK-SAME: !llvm.ptr<array<2 x f32>>
+
+func private @foo6(%arg0: !fir.heap<!fir.array<?x?xf32>>)
+// CHECK-LABEL: foo6
+// CHECK-SAME: !llvm.ptr<f32>
+
+func private @foo7(%arg0: !fir.heap<!fir.type<ZT>>)
+// CHECK-LABEL: foo7
+// CHECK-SAME: !llvm.ptr<struct<"ZT", ()>>
+
+func private @foo8(%arg0: !fir.heap<!fir.type<_QMalloc_assignTt{i:i32}>>)
+// CHECK-LABEL: foo8
+// CHECK-SAME: !llvm.ptr<struct<"_QMalloc_assignTt", (i32)>>
+
+// -----
+
 // Test `!fir.logical<KIND>` conversion.
 
 func private @foo0(%arg0: !fir.logical<1>)
Index: flang/lib/Optimizer/CodeGen/TypeConverter.h
===================================================================
--- flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -52,6 +52,7 @@
     addConversion([&](BoxType box) { return convertBoxType(box); });
     addConversion(
         [&](fir::CharacterType charTy) { return convertCharType(charTy); });
+    addConversion([&](HeapType heap) { return convertPointerLike(heap); });
     addConversion([&](fir::LogicalType boolTy) {
       return mlir::IntegerType::get(
           &getContext(), kindMapping.getLogicalBitsize(boolTy.getFKind()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113670.386495.patch
Type: text/x-patch
Size: 2944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211111/56d86f47/attachment.bin>


More information about the llvm-commits mailing list