From 2b247941cac6c278595b1c86ca3b895bd2b3f056 Mon Sep 17 00:00:00 2001 From: Kiran Chandramohan Date: Fri, 12 Nov 2021 09:35:03 +0000 Subject: [PATCH] [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 Co-authored-by: Jean Perier --- flang/lib/Optimizer/CodeGen/TypeConverter.h | 1 + flang/test/Fir/types-to-llvm.fir | 46 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h index 7295da2..3c21dfa 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -56,6 +56,7 @@ public: }); 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 e872a3a..739a366 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) func private @foo1(%arg0: !fir.ref>) // CHECK-LABEL: foo1 // CHECK-SAME: !llvm.ptr> +func private @foo2(%arg0: !fir.ref>>>) +// CHECK-LABEL: foo2 +// CHECK-SAME: !llvm.ptr>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>> // ----- @@ -61,6 +64,10 @@ func private @foo3(%arg0: !fir.box>) // CHECK-LABEL: foo3 // CHECK-SAME: !llvm.ptr>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>> +func private @foo4(%arg0: !fir.box>>) +// CHECK-LABEL: foo4 +// CHECK-SAME: !llvm.ptr>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>> + // ----- // Test char types `!fir.char` @@ -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) +// CHECK-LABEL: foo0 +// CHECK-SAME: !llvm.ptr + +func private @foo1(%arg0: !fir.heap>) +// CHECK-LABEL: foo1 +// CHECK-SAME: !llvm.ptr> + +func private @foo2(%arg0: !fir.heap>) +// CHECK-LABEL: foo2 +// CHECK-SAME: !llvm.ptr + +func private @foo3(%arg0: !fir.heap>) +// CHECK-LABEL: foo3 +// CHECK-SAME: !llvm.ptr> + +func private @foo4(%arg0: !fir.heap>) +// CHECK-LABEL: foo4 +// CHECK-SAME: !llvm.ptr + +func private @foo5(%arg0: !fir.heap>) +// CHECK-LABEL: foo5 +// CHECK-SAME: !llvm.ptr> + +func private @foo6(%arg0: !fir.heap>) +// CHECK-LABEL: foo6 +// CHECK-SAME: !llvm.ptr + +func private @foo7(%arg0: !fir.heap>) +// CHECK-LABEL: foo7 +// CHECK-SAME: !llvm.ptr> + +func private @foo8(%arg0: !fir.heap>) +// CHECK-LABEL: foo8 +// CHECK-SAME: !llvm.ptr> + +// ----- + // Test `!fir.logical` conversion. func private @foo0(%arg0: !fir.logical<1>) -- 2.7.4