[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>
This commit is contained in:
Diana Picus 2021-11-10 11:26:15 +00:00
parent deafc6fc6d
commit a343b74f85
2 changed files with 33 additions and 0 deletions

View File

@ -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.

View File

@ -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>)