[flang] Enable complex type in function lowering

This patch enables complex 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/D119700

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

View File

@ -75,6 +75,13 @@ static mlir::Type genLogicalType(mlir::MLIRContext *context, int KIND) {
return {};
}
static mlir::Type genComplexType(mlir::MLIRContext *context, int KIND) {
if (Fortran::evaluate::IsValidKindOfIntrinsicType(
Fortran::common::TypeCategory::Complex, KIND))
return fir::ComplexType::get(context, KIND);
return {};
}
static mlir::Type genFIRType(mlir::MLIRContext *context,
Fortran::common::TypeCategory tc, int kind) {
switch (tc) {
@ -83,7 +90,7 @@ static mlir::Type genFIRType(mlir::MLIRContext *context,
case Fortran::common::TypeCategory::Integer:
return genIntegerType(context, kind);
case Fortran::common::TypeCategory::Complex:
TODO_NOLOC("genFIRType Complex");
return genComplexType(context, kind);
case Fortran::common::TypeCategory::Logical:
return genLogicalType(context, kind);
case Fortran::common::TypeCategory::Character:
@ -138,16 +145,6 @@ genFIRType<Fortran::common::TypeCategory::Character>(mlir::MLIRContext *context,
return {};
}
template <>
mlir::Type
genFIRType<Fortran::common::TypeCategory::Complex>(mlir::MLIRContext *context,
int KIND) {
if (Fortran::evaluate::IsValidKindOfIntrinsicType(
Fortran::common::TypeCategory::Complex, KIND))
return fir::ComplexType::get(context, KIND);
return {};
}
namespace {
/// Discover the type of an Fortran::evaluate::Expr<T> and convert it to an

View File

@ -98,3 +98,32 @@ end
! CHECK-LABEL: func @_QPrfct6() -> f128
! CHECK: return %{{.*}} : f128
complex(2) function cplxfct1()
end
! CHECK-LABEL: func @_QPcplxfct1() -> !fir.complex<2>
! CHECK: return %{{.*}} : !fir.complex<2>
complex(3) function cplxfct2()
end
! CHECK-LABEL: func @_QPcplxfct2() -> !fir.complex<3>
! CHECK: return %{{.*}} : !fir.complex<3>
complex(4) function cplxfct3()
end
! CHECK-LABEL: func @_QPcplxfct3() -> !fir.complex<4>
! CHECK: return %{{.*}} : !fir.complex<4>
complex(8) function cplxfct4()
end
! CHECK-LABEL: func @_QPcplxfct4() -> !fir.complex<8>
! CHECK: return %{{.*}} : !fir.complex<8>
complex(10) function cplxfct5()
end
! CHECK-LABEL: func @_QPcplxfct5() -> !fir.complex<10>
! CHECK: return %{{.*}} : !fir.complex<10>
complex(16) function cplxfct6()
end
! CHECK-LABEL: func @_QPcplxfct6() -> !fir.complex<16>
! CHECK: return %{{.*}} : !fir.complex<16>