[flang-commits] [flang] efd3d87 - [flang][hlfir] Lower asInquired intrinsic arguments

Jean Perier via flang-commits flang-commits at lists.llvm.org
Sun Feb 5 23:54:33 PST 2023


Author: Jean Perier
Date: 2023-02-06T08:54:17+01:00
New Revision: efd3d8754318e2a242e849e452f05346dc291db3

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

LOG: [flang][hlfir] Lower asInquired intrinsic arguments

Differential Revision: https://reviews.llvm.org/D143272

Added: 
    flang/test/Lower/HLFIR/expr-as-inquired.f90

Modified: 
    flang/lib/Lower/ConvertCall.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index 9ce10c0859f36..31fb6339f8fdc 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -1115,7 +1115,15 @@ static std::optional<hlfir::EntityWithAttributes> genIntrinsicRefCore(
           Fortran::lower::convertToBox(loc, converter, actual, stmtCtx));
       continue;
     case Fortran::lower::LowerIntrinsicArgAs::Inquired:
-      TODO(loc, "as inquired arguments in HLFIR");
+      // Place hlfir.expr in memory, and unbox fir.boxchar. Other entities
+      // are translated to fir::ExtendedValue without transformation (notably,
+      // pointers/allocatable are not dereferenced).
+      // TODO: once lowering to FIR retires, UBOUND and LBOUND can be simplified
+      // since the fir.box lowered here are now guaranteed to contain the local
+      // lower bounds thanks to the hlfir.declare (the extra rebox can be
+      // removed).
+      operands.emplace_back(Fortran::lower::translateToExtendedValue(
+          loc, builder, actual, stmtCtx));
       continue;
     }
     llvm_unreachable("bad switch");

diff  --git a/flang/test/Lower/HLFIR/expr-as-inquired.f90 b/flang/test/Lower/HLFIR/expr-as-inquired.f90
new file mode 100644
index 0000000000000..9dac1006649e5
--- /dev/null
+++ b/flang/test/Lower/HLFIR/expr-as-inquired.f90
@@ -0,0 +1,41 @@
+! Test lowering to HLFIR of the intrinsic lowering framework
+! "asInquired" option.
+
+! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
+
+subroutine test_isAllocated(x, l)
+  logical :: l
+  real, allocatable :: x(:)
+  l = allocated(x)
+end subroutine
+! CHECK-LABEL: func.func @_QPtest_isallocated(
+! CHECK:  %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}}  {{.*}}El
+! CHECK:  %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, {{.*}}Ex"
+! CHECK:  %[[VAL_4:.*]] = fir.load %[[VAL_3]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
+! CHECK:  %[[VAL_5:.*]] = fir.box_addr %[[VAL_4]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
+! CHECK:  %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.heap<!fir.array<?xf32>>) -> i64
+! CHECK:  %[[VAL_7:.*]] = arith.constant 0 : i64
+! CHECK:  %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64
+! CHECK:  hlfir.assign %[[VAL_8]] to %[[VAL_2]]#0 : i1, !fir.ref<!fir.logical<4>>
+! CHECK:  return
+! CHECK:  }
+
+subroutine test_lbound(x, n)
+  integer :: n
+  real :: x(2:, 3:)
+  n = lbound(x, dim=n)
+end subroutine
+! CHECK-LABEL: func.func @_QPtest_lbound(
+! CHECK:  %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}  {{.*}}En
+! CHECK:  %[[VAL_5:.*]] = arith.constant 2 : i64
+! CHECK:  %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i64) -> index
+! CHECK:  %[[VAL_7:.*]] = arith.constant 3 : i64
+! CHECK:  %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
+! CHECK:  %[[VAL_10:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}})  {{.*}}Ex
+! CHECK:  %[[VAL_11:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<i32>
+! CHECK:  %[[VAL_12:.*]] = fir.shift %[[VAL_6]], %[[VAL_8]] : (index, index) -> !fir.shift<2>
+! CHECK:  %[[VAL_13:.*]] = fir.rebox %[[VAL_10]]#1(%[[VAL_12]]) : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
+! CHECK:  %[[VAL_16:.*]] = fir.convert %[[VAL_13]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
+! CHECK:  %[[VAL_18:.*]] = fir.call @_FortranALboundDim(%[[VAL_16]],
+! CHECK:  %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i64) -> i32
+! CHECK:  hlfir.assign %[[VAL_19]] to %[[VAL_4]]#0 : i32, !fir.ref<i32>


        


More information about the flang-commits mailing list