[flang] Enable scalar real type in lowering

This patch enables scalar real type in lowering.
It is tested on function return types.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D119698

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D119699

Co-authored-by: Jean Perier <jperier@nvidia.com>
This commit is contained in:
Valentin Clement 2022-02-15 08:23:00 +01:00
parent cc120e36c3
commit 0a0b3029de
No known key found for this signature in database
GPG key ID: 086D54783C928776
2 changed files with 53 additions and 61 deletions

View file

@ -23,6 +23,27 @@
// Intrinsic type translation helpers // Intrinsic type translation helpers
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
static mlir::Type genRealType(mlir::MLIRContext *context, int kind) {
if (Fortran::evaluate::IsValidKindOfIntrinsicType(
Fortran::common::TypeCategory::Real, kind)) {
switch (kind) {
case 2:
return mlir::FloatType::getF16(context);
case 3:
return mlir::FloatType::getBF16(context);
case 4:
return mlir::FloatType::getF32(context);
case 8:
return mlir::FloatType::getF64(context);
case 10:
return mlir::FloatType::getF80(context);
case 16:
return mlir::FloatType::getF128(context);
}
}
llvm_unreachable("REAL type translation not implemented");
}
template <int KIND> template <int KIND>
int getIntegerBits() { int getIntegerBits() {
return Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, return Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer,
@ -58,7 +79,7 @@ static mlir::Type genFIRType(mlir::MLIRContext *context,
Fortran::common::TypeCategory tc, int kind) { Fortran::common::TypeCategory tc, int kind) {
switch (tc) { switch (tc) {
case Fortran::common::TypeCategory::Real: case Fortran::common::TypeCategory::Real:
TODO_NOLOC("genFIRType Real"); return genRealType(context, kind);
case Fortran::common::TypeCategory::Integer: case Fortran::common::TypeCategory::Integer:
return genIntegerType(context, kind); return genIntegerType(context, kind);
case Fortran::common::TypeCategory::Complex: case Fortran::common::TypeCategory::Complex:
@ -107,66 +128,6 @@ mlir::Type genFIRType(mlir::MLIRContext *context) {
} }
} }
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Real, 2>(mlir::MLIRContext *context) {
return mlir::FloatType::getF16(context);
}
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Real, 3>(mlir::MLIRContext *context) {
return mlir::FloatType::getBF16(context);
}
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Real, 4>(mlir::MLIRContext *context) {
return mlir::FloatType::getF32(context);
}
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Real, 8>(mlir::MLIRContext *context) {
return mlir::FloatType::getF64(context);
}
template <>
mlir::Type genFIRType<Fortran::common::TypeCategory::Real, 10>(
mlir::MLIRContext *context) {
return fir::RealType::get(context, 10);
}
template <>
mlir::Type genFIRType<Fortran::common::TypeCategory::Real, 16>(
mlir::MLIRContext *context) {
return fir::RealType::get(context, 16);
}
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Real>(mlir::MLIRContext *context,
int kind) {
if (Fortran::evaluate::IsValidKindOfIntrinsicType(
Fortran::common::TypeCategory::Real, kind)) {
switch (kind) {
case 2:
return genFIRType<Fortran::common::TypeCategory::Real, 2>(context);
case 3:
return genFIRType<Fortran::common::TypeCategory::Real, 3>(context);
case 4:
return genFIRType<Fortran::common::TypeCategory::Real, 4>(context);
case 8:
return genFIRType<Fortran::common::TypeCategory::Real, 8>(context);
case 10:
return genFIRType<Fortran::common::TypeCategory::Real, 10>(context);
case 16:
return genFIRType<Fortran::common::TypeCategory::Real, 16>(context);
}
}
llvm_unreachable("REAL type translation not implemented");
}
template <> template <>
mlir::Type mlir::Type
genFIRType<Fortran::common::TypeCategory::Character>(mlir::MLIRContext *context, genFIRType<Fortran::common::TypeCategory::Character>(mlir::MLIRContext *context,

View file

@ -67,3 +67,34 @@ logical(8) function lfct4()
end end
! CHECK-LABEL: func @_QPlfct4() -> !fir.logical<8> ! CHECK-LABEL: func @_QPlfct4() -> !fir.logical<8>
! CHECK: return %{{.*}} : !fir.logical<8> ! CHECK: return %{{.*}} : !fir.logical<8>
real(2) function rfct1()
end
! CHECK-LABEL: func @_QPrfct1() -> f16
! CHECK: return %{{.*}} : f16
real(3) function rfct2()
end
! CHECK-LABEL: func @_QPrfct2() -> bf16
! CHECK: return %{{.*}} : bf16
real function rfct3()
end
! CHECK-LABEL: func @_QPrfct3() -> f32
! CHECK: return %{{.*}} : f32
real(8) function rfct4()
end
! CHECK-LABEL: func @_QPrfct4() -> f64
! CHECK: return %{{.*}} : f64
real(10) function rfct5()
end
! CHECK-LABEL: func @_QPrfct5() -> f80
! CHECK: return %{{.*}} : f80
real(16) function rfct6()
end
! CHECK-LABEL: func @_QPrfct6() -> f128
! CHECK: return %{{.*}} : f128