diff options
author | Diana Picus <diana.picus@linaro.org> | 2021-11-10 11:26:15 +0000 |
---|---|---|
committer | Diana Picus <diana.picus@linaro.org> | 2021-11-10 12:27:58 +0000 |
commit | a343b74f8532c8e04e600d5d6e1ba7959f950808 (patch) | |
tree | a86e2da4ed10632b877ffc7832c3f9fa52aa28d7 | |
parent | deafc6fc6de6bb0781984c0a0182a7b75c55926e (diff) | |
download | llvm-a343b74f8532c8e04e600d5d6e1ba7959f950808.zip llvm-a343b74f8532c8e04e600d5d6e1ba7959f950808.tar.gz llvm-a343b74f8532c8e04e600d5d6e1ba7959f950808.tar.bz2 |
[fir] Add !fir.char type conversion
This patch is part of the upstreaming effort from fir-dev.
Differential Revision: https://reviews.llvm.org/D113560
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
-rw-r--r-- | flang/lib/Optimizer/CodeGen/TypeConverter.h | 14 | ||||
-rw-r--r-- | flang/test/Fir/types-to-llvm.fir | 19 |
2 files changed, 33 insertions, 0 deletions
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h index 2f5eb06..b73ece7 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -37,6 +37,8 @@ public: // 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 @@ public: /*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. diff --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir index 94b1a0b..921ac35 100644 --- a/flang/test/Fir/types-to-llvm.fir +++ b/flang/test/Fir/types-to-llvm.fir @@ -63,6 +63,25 @@ func private @foo3(%arg0: !fir.box<!fir.type<derived{f:f32}>>) // ----- +// 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>) |