[flang-commits] [flang] 18c6b05 - [flang] is_iostat_end and is_iostat_eor intrinsics

V Donaldson via flang-commits flang-commits at lists.llvm.org
Wed Mar 8 13:27:36 PST 2023


Author: V Donaldson
Date: 2023-03-08T13:27:16-08:00
New Revision: 18c6b057a7360dfec31e9ccbcbed5b3be471a7ca

URL: https://github.com/llvm/llvm-project/commit/18c6b057a7360dfec31e9ccbcbed5b3be471a7ca
DIFF: https://github.com/llvm/llvm-project/commit/18c6b057a7360dfec31e9ccbcbed5b3be471a7ca.diff

LOG: [flang] is_iostat_end and is_iostat_eor intrinsics

Added: 
    flang/test/Lower/Intrinsics/is_iostat_value.f90

Modified: 
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 26ea98c3f5e02..787a55e1341b6 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -37,6 +37,7 @@
 #include "flang/Optimizer/Support/FatalError.h"
 #include "flang/Optimizer/Support/Utils.h"
 #include "flang/Runtime/entry-names.h"
+#include "flang/Runtime/iostat.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/Math/IR/Math.h"
@@ -253,6 +254,8 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genIparity(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genIsContiguous(mlir::Type,
                                      llvm::ArrayRef<fir::ExtendedValue>);
+  template <Fortran::runtime::io::Iostat value>
+  mlir::Value genIsIostatValue(mlir::Type, llvm::ArrayRef<mlir::Value>);
   mlir::Value genIsNan(mlir::Type, llvm::ArrayRef<mlir::Value>);
   mlir::Value genIsFPClass(mlir::Type, llvm::ArrayRef<mlir::Value>,
                            int fpclass);
@@ -650,6 +653,8 @@ static constexpr IntrinsicHandler handlers[]{
      &I::genIsContiguous,
      {{{"array", asBox}}},
      /*isElemental=*/false},
+    {"is_iostat_end", &I::genIsIostatValue<Fortran::runtime::io::IostatEnd>},
+    {"is_iostat_eor", &I::genIsIostatValue<Fortran::runtime::io::IostatEor>},
     {"ishft", &I::genIshft},
     {"ishftc", &I::genIshftc},
     {"isnan", &I::genIsNan},
@@ -3071,8 +3076,8 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType,
 
   // Create mutable fir.box to be passed to the runtime for the result.
   mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, arrayRank);
-  fir::MutableBoxValue resultMutableBox =
-      fir::factory::createTempMutableBox(builder, loc, resultArrayType, {},
+  fir::MutableBoxValue resultMutableBox = fir::factory::createTempMutableBox(
+      builder, loc, resultArrayType, {},
       fir::isPolymorphicType(array.getType()) ? array : mlir::Value{});
   mlir::Value resultIrBox =
       fir::factory::getMutableIRBox(builder, loc, resultMutableBox);
@@ -3734,6 +3739,17 @@ IntrinsicLibrary::genIsContiguous(mlir::Type resultType,
       fir::runtime::genIsContiguous(builder, loc, fir::getBase(args[0])));
 }
 
+// IS_IOSTAT_END, IS_IOSTAT_EOR
+template <Fortran::runtime::io::Iostat value>
+mlir::Value
+IntrinsicLibrary::genIsIostatValue(mlir::Type resultType,
+                                   llvm::ArrayRef<mlir::Value> args) {
+  assert(args.size() == 1);
+  return builder.create<mlir::arith::CmpIOp>(
+      loc, mlir::arith::CmpIPredicate::eq, args[0],
+      builder.createIntegerConstant(loc, args[0].getType(), value));
+}
+
 mlir::Value IntrinsicLibrary::genIsFPClass(mlir::Type resultType,
                                            llvm::ArrayRef<mlir::Value> args,
                                            int fpclass) {
@@ -5047,8 +5063,8 @@ IntrinsicLibrary::genTransfer(mlir::Type resultType,
   mlir::Type type = (moldRank == 0 && absentSize)
                         ? resultType
                         : builder.getVarLenSeqTy(resultType, 1);
-  fir::MutableBoxValue resultMutableBox =
-      fir::factory::createTempMutableBox(builder, loc, type, {},
+  fir::MutableBoxValue resultMutableBox = fir::factory::createTempMutableBox(
+      builder, loc, type, {},
       fir::isPolymorphicType(mold.getType()) ? mold : mlir::Value{});
 
   if (moldRank == 0 && absentSize) {

diff  --git a/flang/test/Lower/Intrinsics/is_iostat_value.f90 b/flang/test/Lower/Intrinsics/is_iostat_value.f90
new file mode 100644
index 0000000000000..933dca1dcf193
--- /dev/null
+++ b/flang/test/Lower/Intrinsics/is_iostat_value.f90
@@ -0,0 +1,23 @@
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+  ! CHECK-LABEL: func @_QQmain
+  ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
+  ! CHECK: fir.do_loop
+  do i=-20,20
+    ! CHECK: %[[V_5:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
+    ! CHECK: %[[V_6:[0-9]+]] = arith.cmpi eq, %[[V_5]], %c-1{{.*}} : i32
+    ! CHECK: fir.if %[[V_6]] {
+    ! CHECK:   %[[V_20:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
+    ! CHECK:   %[[V_21:[0-9]+]] = fir.call @_FortranAioOutputInteger32(%{{.*}} %[[V_20]]) fastmath<contract> : (!fir.ref<i8>, i32) -> i1
+    ! CHECK: }
+    if (is_iostat_end(i)) print*, "iostat_end =", i
+    ! CHECK: %[[V_7:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
+    ! CHECK: %[[V_8:[0-9]+]] = arith.cmpi eq, %[[V_7]], %c-2{{.*}} : i32
+    ! CHECK: fir.if %[[V_8]] {
+    ! CHECK:   %[[V_20:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
+    ! CHECK:   %[[V_21:[0-9]+]] = fir.call @_FortranAioOutputInteger32(%{{.*}} %[[V_20]]) fastmath<contract> : (!fir.ref<i8>, i32) -> i1
+    ! CHECK: }
+    if (is_iostat_eor(i)) print*, "iostat_eor =", i
+  ! CHECK: }
+  enddo
+end


        


More information about the flang-commits mailing list