diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -486,9 +486,13 @@ void genRandomInit(llvm::ArrayRef); void genRandomNumber(llvm::ArrayRef); void genRandomSeed(llvm::ArrayRef); + mlir::Value genRRSpacing(mlir::Type resultType, + llvm::ArrayRef args); mlir::Value genSetExponent(mlir::Type resultType, llvm::ArrayRef args); fir::ExtendedValue genSize(mlir::Type, llvm::ArrayRef); + mlir::Value genSpacing(mlir::Type resultType, + llvm::ArrayRef args); fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef); void genSystemClock(llvm::ArrayRef); fir::ExtendedValue genTransfer(mlir::Type, @@ -727,6 +731,7 @@ &I::genRandomSeed, {{{"size", asBox}, {"put", asBox}, {"get", asBox}}}, /*isElemental=*/false}, + {"rrspacing", &I::genRRSpacing}, {"set_exponent", &I::genSetExponent}, {"size", &I::genSize, @@ -734,6 +739,7 @@ {"dim", asAddr, handleDynamicOptional}, {"kind", asValue}}}, /*isElemental=*/false}, + {"spacing", &I::genSpacing}, {"sum", &I::genSum, {{{"array", asBox}, @@ -2485,6 +2491,16 @@ Fortran::lower::genRandomSeed(builder, loc, -1, mlir::Value{}); } +// RRSPACING +mlir::Value IntrinsicLibrary::genRRSpacing(mlir::Type resultType, + llvm::ArrayRef args) { + assert(args.size() == 1); + + return builder.createConvert( + loc, resultType, + fir::runtime::genRRSpacing(builder, loc, fir::getBase(args[0]))); +} + // SET_EXPONENT mlir::Value IntrinsicLibrary::genSetExponent(mlir::Type resultType, llvm::ArrayRef args) { @@ -2496,6 +2512,16 @@ fir::getBase(args[1]))); } +// SPACING +mlir::Value IntrinsicLibrary::genSpacing(mlir::Type resultType, + llvm::ArrayRef args) { + assert(args.size() == 1); + + return builder.createConvert( + loc, resultType, + fir::runtime::genSpacing(builder, loc, fir::getBase(args[0]))); +} + // SUM fir::ExtendedValue IntrinsicLibrary::genSum(mlir::Type resultType, diff --git a/flang/test/Lower/Intrinsics/rrspacing.f90 b/flang/test/Lower/Intrinsics/rrspacing.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/Intrinsics/rrspacing.f90 @@ -0,0 +1,11 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: func @_QPrrspacing_test2( +! CHECK-SAME: %[[x:[^:]+]]: !fir.ref{{.*}}) -> f128 +real*16 function rrspacing_test2(x) + real*16 :: x + rrspacing_test2 = rrspacing(x) +! CHECK: %[[a1:.*]] = fir.load %[[x]] : !fir.ref +! CHECK: %{{.*}} = fir.call @_FortranARRSpacing16(%[[a1]]) : (f128) -> f128 +end function diff --git a/flang/test/Lower/Intrinsics/spacing.f90 b/flang/test/Lower/Intrinsics/spacing.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/Intrinsics/spacing.f90 @@ -0,0 +1,20 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: func @_QPspacing_test( +! CHECK-SAME: %[[x:[^:]+]]: !fir.ref{{.*}}) -> f32 +real*4 function spacing_test(x) + real*4 :: x + spacing_test = spacing(x) +! CHECK: %[[a1:.*]] = fir.load %[[x]] : !fir.ref +! CHECK: %{{.*}} = fir.call @_FortranASpacing4(%[[a1]]) : (f32) -> f32 +end function + +! CHECK-LABEL: func @_QPspacing_test2( +! CHECK-SAME: %[[x:[^:]+]]: !fir.ref{{.*}}) -> f80 +real*10 function spacing_test2(x) + real*10 :: x + spacing_test2 = spacing(x) +! CHECK: %[[a1:.*]] = fir.load %[[x]] : !fir.ref +! CHECK: %{{.*}} = fir.call @_FortranASpacing10(%[[a1]]) : (f80) -> f80 +end function