[PATCH] D113571: [flang][codegen] Add type conversion for `fir.boxchar`
Andrzej Warzynski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 10 08:04:48 PST 2021
awarzynski created this revision.
awarzynski added reviewers: clementval, schweitz, rovka, jeanPerier, kiranchandramohan.
Herald added a subscriber: mehdi_amini.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
This is part of the upstreaming effort from the `fir-dev` branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project
Patch originally written by:
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/D113571
Files:
flang/lib/Optimizer/CodeGen/Target.cpp
flang/lib/Optimizer/CodeGen/Target.h
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
@@ -131,3 +131,15 @@
func private @foo5(%arg0: !fir.complex<16>)
// CHECK-LABEL: foo5
// CHECK-SAME: !llvm.struct<(f128, f128)>)
+
+// -----
+
+// Test `!fir.boxchar<n>` conversion
+
+func private @foo0(%arg0: !fir.boxchar<1>)
+// CHECK-LABEL: foo0
+// CHECK-SAME: !llvm.struct<(ptr<i8>, i64)>
+
+func private @foo1(%arg0: !fir.boxchar<2>)
+// CHECK-LABEL: foo1
+// CHECK-SAME: !llvm.struct<(ptr<i16>, i64)>
Index: flang/lib/Optimizer/CodeGen/TypeConverter.h
===================================================================
--- flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -40,6 +40,10 @@
// Each conversion should return a value of type mlir::Type.
addConversion([&](BoxType box) { return convertBoxType(box); });
+ addConversion([&](BoxCharType boxchar) {
+ LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n');
+ return convertType(specifics->boxcharMemoryType(boxchar.getEleTy()));
+ });
addConversion(
[&](fir::CharacterType charTy) { return convertCharType(charTy); });
addConversion([&](fir::LogicalType boolTy) {
Index: flang/lib/Optimizer/CodeGen/Target.h
===================================================================
--- flang/lib/Optimizer/CodeGen/Target.h
+++ flang/lib/Optimizer/CodeGen/Target.h
@@ -77,6 +77,9 @@
/// value may need to be converted to a hidden reference argument.
virtual Marshalling complexReturnType(mlir::Type eleTy) const = 0;
+ /// Type presentation of a `boxchar<n>` type value in memory.
+ virtual mlir::Type boxcharMemoryType(mlir::Type eleTy) const = 0;
+
/// Type representation of a `boxchar<n>` type argument when passed by value.
/// An argument value may need to be passed as a (safe) reference argument.
///
Index: flang/lib/Optimizer/CodeGen/Target.cpp
===================================================================
--- flang/lib/Optimizer/CodeGen/Target.cpp
+++ flang/lib/Optimizer/CodeGen/Target.cpp
@@ -42,6 +42,14 @@
return mlir::TupleType::get(eleTy.getContext(), range);
}
+ mlir::Type boxcharMemoryType(mlir::Type eleTy) const override {
+ auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth);
+ auto ptrTy = fir::ReferenceType::get(eleTy);
+ // { t*, index }
+ mlir::TypeRange range = {ptrTy, idxTy};
+ return mlir::TupleType::get(eleTy.getContext(), range);
+ }
+
Marshalling boxcharArgumentType(mlir::Type eleTy, bool sret) const override {
CodeGenSpecifics::Marshalling marshal;
auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113571.386174.patch
Type: text/x-patch
Size: 2796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211110/e8a060ef/attachment.bin>
More information about the llvm-commits
mailing list