[flang-commits] [flang] 2b24794 - [Flang] Add type conversion for FIR heap type
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Fri Nov 12 01:50:45 PST 2021
Author: Kiran Chandramohan
Date: 2021-11-12T09:49:54Z
New Revision: 2b247941cac6c278595b1c86ca3b895bd2b3f056
URL: https://github.com/llvm/llvm-project/commit/2b247941cac6c278595b1c86ca3b895bd2b3f056
DIFF: https://github.com/llvm/llvm-project/commit/2b247941cac6c278595b1c86ca3b895bd2b3f056.diff
LOG: [Flang] Add type conversion for FIR heap type
Convert fir.heap type to its llvm equivalent type (llvm.ptr)
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: clementval
Differential Revision: https://reviews.llvm.org/D113670
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 7295da2a4e29..3c21dfa50443 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -56,6 +56,7 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
});
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()));
diff --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir
index e872a3a514ac..739a36647750 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -28,6 +28,9 @@ func private @foo0(%arg0: !fir.ref<i32>)
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)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
// -----
@@ -61,6 +64,10 @@ func private @foo3(%arg0: !fir.box<!fir.type<derived{f:f32}>>)
// 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)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
+
// -----
// Test char types `!fir.char<k, n>`
@@ -82,6 +89,45 @@ func private @foo2(%arg0: !fir.char<4, 8>, %arg1: !fir.char<4, ?>)
// -----
+// 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>)
More information about the flang-commits
mailing list