[flang-commits] [PATCH] D113560: [fir] Add !fir.char type conversion
Diana Picus via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Nov 10 04:29:09 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa343b74f8532: [fir] Add !fir.char type conversion (authored by rovka).
Changed prior to commit:
https://reviews.llvm.org/D113560?vs=386118&id=386122#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113560/new/
https://reviews.llvm.org/D113560
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
@@ -63,6 +63,25 @@
// -----
+// Test char types `!fir.char<k, n>`
+
+func private @foo0(%arg0: !fir.char<1, 4>, %arg1: !fir.char<1, ?>)
+// CHECK-LABEL: foo0
+// CHECK-SAME: !llvm.array<4 x i8>
+// CHECK-SAME: i8
+
+func private @foo1(%arg0: !fir.char<2, 12>, %arg1: !fir.char<2, ?>)
+// CHECK-LABEL: foo1
+// CHECK-SAME: !llvm.array<12 x i16>
+// CHECK-SAME: i16
+
+func private @foo2(%arg0: !fir.char<4, 8>, %arg1: !fir.char<4, ?>)
+// CHECK-LABEL: foo2
+// CHECK-SAME: !llvm.array<8 x i32>
+// CHECK-SAME: 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
@@ -37,6 +37,8 @@
// Each conversion should return a value of type mlir::Type.
addConversion([&](BoxType box) { return convertBoxType(box); });
+ addConversion(
+ [&](fir::CharacterType charTy) { return convertCharType(charTy); });
addConversion([&](fir::LogicalType boolTy) {
return mlir::IntegerType::get(
&getContext(), kindMapping.getLogicalBitsize(boolTy.getFKind()));
@@ -150,6 +152,18 @@
/*isPacked=*/false));
}
+ unsigned characterBitsize(fir::CharacterType charTy) {
+ return kindMapping.getCharacterBitsize(charTy.getFKind());
+ }
+
+ // fir.char<n> --> llvm<"ix*"> where ix is scaled by kind mapping
+ mlir::Type convertCharType(fir::CharacterType charTy) {
+ auto iTy = mlir::IntegerType::get(&getContext(), characterBitsize(charTy));
+ if (charTy.getLen() == fir::CharacterType::unknownLen())
+ return iTy;
+ return mlir::LLVM::LLVMArrayType::get(iTy, charTy.getLen());
+ }
+
// Use the target specifics to figure out how to map complex to LLVM IR. The
// use of complex values in function signatures is handled before conversion
// to LLVM IR dialect here.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113560.386122.patch
Type: text/x-patch
Size: 2221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211110/670e8b6b/attachment-0001.bin>
More information about the flang-commits
mailing list