diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp --- a/flang/lib/Lower/ConvertType.cpp +++ b/flang/lib/Lower/ConvertType.cpp @@ -23,6 +23,27 @@ // 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 getIntegerBits() { return Fortran::evaluate::Type -mlir::Type -genFIRType(mlir::MLIRContext *context) { - return mlir::FloatType::getF16(context); -} - -template <> -mlir::Type -genFIRType(mlir::MLIRContext *context) { - return mlir::FloatType::getBF16(context); -} - -template <> -mlir::Type -genFIRType(mlir::MLIRContext *context) { - return mlir::FloatType::getF32(context); -} - -template <> -mlir::Type -genFIRType(mlir::MLIRContext *context) { - return mlir::FloatType::getF64(context); -} - -template <> -mlir::Type genFIRType( - mlir::MLIRContext *context) { - return fir::RealType::get(context, 10); -} - -template <> -mlir::Type genFIRType( - mlir::MLIRContext *context) { - return fir::RealType::get(context, 16); -} - -template <> -mlir::Type -genFIRType(mlir::MLIRContext *context, - int kind) { - if (Fortran::evaluate::IsValidKindOfIntrinsicType( - Fortran::common::TypeCategory::Real, kind)) { - switch (kind) { - case 2: - return genFIRType(context); - case 3: - return genFIRType(context); - case 4: - return genFIRType(context); - case 8: - return genFIRType(context); - case 10: - return genFIRType(context); - case 16: - return genFIRType(context); - } - } - llvm_unreachable("REAL type translation not implemented"); -} - template <> mlir::Type genFIRType(mlir::MLIRContext *context, diff --git a/flang/test/Lower/basic-function.f90 b/flang/test/Lower/basic-function.f90 --- a/flang/test/Lower/basic-function.f90 +++ b/flang/test/Lower/basic-function.f90 @@ -30,3 +30,34 @@ end ! CHECK-LABEL: func @_QPfct() -> i32 ! CHECK: return %{{.*}} : i32 + +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 +