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 @@ -26,6 +26,7 @@ #include "flang/Optimizer/Builder/MutableBox.h" #include "flang/Optimizer/Builder/Runtime/Character.h" #include "flang/Optimizer/Builder/Runtime/Inquiry.h" +#include "flang/Optimizer/Builder/Runtime/Numeric.h" #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" #include "flang/Optimizer/Builder/Runtime/Reduction.h" #include "flang/Optimizer/Dialect/FIROpsSupport.h" @@ -465,13 +466,16 @@ void genRandomInit(llvm::ArrayRef); void genRandomNumber(llvm::ArrayRef); void genRandomSeed(llvm::ArrayRef); + mlir::Value genRRSpacing(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, llvm::ArrayRef); fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef); - /// Define the different FIR generators that can be mapped to intrinsic to /// generate the related code. using ElementalGenerator = decltype(&IntrinsicLibrary::genAbs); @@ -663,6 +667,8 @@ &I::genRandomSeed, {{{"size", asBox}, {"put", asBox}, {"get", asBox}}}, /*isElemental=*/false}, + {"rrspacing", &I::genRRSpacing}, + {"spacing", &I::genSpacing}, {"sum", &I::genSum, {{{"array", asBox}, @@ -1937,6 +1943,26 @@ 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]))); +} + +// 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