Skip to content

Commit 887bd73

Browse files
authored
[flang] Handle procedure pointer and dummy procecure in REDUCE intrinsic calls (#95843)
Add handling for procedure pointer and dummy procedure in REDUCE intrinsic call lowering.
1 parent 3d2bbea commit 887bd73

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5747,10 +5747,18 @@ IntrinsicLibrary::genReduce(mlir::Type resultType,
57475747

57485748
// Arguements to the reduction operation are passed by reference or value?
57495749
bool argByRef = true;
5750+
if (!operation.getDefiningOp())
5751+
TODO(loc, "Distinguigh dummy procedure arguments");
57505752
if (auto embox =
57515753
mlir::dyn_cast_or_null<fir::EmboxProcOp>(operation.getDefiningOp())) {
57525754
auto fctTy = mlir::dyn_cast<mlir::FunctionType>(embox.getFunc().getType());
57535755
argByRef = mlir::isa<fir::ReferenceType>(fctTy.getInput(0));
5756+
} else if (auto load = mlir::dyn_cast_or_null<fir::LoadOp>(
5757+
operation.getDefiningOp())) {
5758+
auto boxProcTy = mlir::dyn_cast_or_null<fir::BoxProcType>(load.getType());
5759+
assert(boxProcTy && "expect BoxProcType");
5760+
auto fctTy = mlir::dyn_cast<mlir::FunctionType>(boxProcTy.getEleTy());
5761+
argByRef = mlir::isa<fir::ReferenceType>(fctTy.getInput(0));
57545762
}
57555763

57565764
mlir::Type ty = array.getType();

flang/test/Lower/Intrinsics/reduce.f90

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ module reduce_mod
66
integer :: a
77
end type
88

9+
abstract interface
10+
pure function red_int1_interface(a, b)
11+
integer(1), intent(in) :: a, b
12+
integer(1) :: red_int1_interface
13+
end function
14+
pure function red_int1_interface_value(a, b)
15+
integer(1), value, intent(in) :: a, b
16+
integer(1) :: red_int1_interface_value
17+
end function
18+
end interface
19+
920
contains
1021

1122
pure function red_int1(a,b)
@@ -20,9 +31,13 @@ pure function red_int1_value(a,b)
2031
red_int1_value = a + b
2132
end function
2233

23-
subroutine integer1(a, id)
34+
subroutine integer1(a, id, d1, d2)
2435
integer(1), intent(in) :: a(:)
2536
integer(1) :: res, id
37+
procedure(red_int1_interface), pointer :: fptr
38+
procedure(red_int1_interface_value), pointer :: fptr_value
39+
procedure(red_int1_interface) :: d1
40+
procedure(red_int1_interface_value) :: d2
2641

2742
res = reduce(a, red_int1)
2843

@@ -33,10 +48,19 @@ subroutine integer1(a, id)
3348
res = reduce(a, red_int1, [.true., .true., .false.])
3449

3550
res = reduce(a, red_int1_value)
51+
52+
fptr => red_int1
53+
res = reduce(a, fptr)
54+
55+
fptr_value => red_int1_value
56+
res = reduce(a, fptr_value)
57+
58+
!res = reduce(a, d1)
59+
!res = reduce(a, d2)
3660
end subroutine
3761

3862
! CHECK-LABEL: func.func @_QMreduce_modPinteger1(
39-
! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xi8>> {fir.bindc_name = "a"}, %[[ARG1:.*]]: !fir.ref<i8> {fir.bindc_name = "id"})
63+
! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xi8>> {fir.bindc_name = "a"}, %[[ARG1:.*]]: !fir.ref<i8> {fir.bindc_name = "id"}
4064
! CHECK: %[[A:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QMreduce_modFinteger1Ea"} : (!fir.box<!fir.array<?xi8>>, !fir.dscope) -> (!fir.box<!fir.array<?xi8>>, !fir.box<!fir.array<?xi8>>)
4165
! CHECK: %[[ID:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{.*}} {uniq_name = "_QMreduce_modFinteger1Eid"} : (!fir.ref<i8>, !fir.dscope) -> (!fir.ref<i8>, !fir.ref<i8>)
4266
! CHECK: %[[ALLOC_RES:.*]] = fir.alloca i8 {bindc_name = "res", uniq_name = "_QMreduce_modFinteger1Eres"}
@@ -64,6 +88,10 @@ subroutine integer1(a, id)
6488
! CHECK: %[[CONV_MASK:.*]] = fir.convert %[[BOXED_MASK]] : (!fir.box<!fir.array<3x!fir.logical<4>>>) -> !fir.box<none>
6589
! CHECK: fir.call @_FortranAReduceInteger1Ref(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[CONV_MASK]], %{{.*}}, %false{{.*}})
6690
! CHECK: fir.call @_FortranAReduceInteger1Value
91+
! CHECK: fir.call @_FortranAReduceInteger1Ref
92+
! CHECK: fir.call @_FortranAReduceInteger1Value
93+
! TODO fir.call @_FortranAReduceInteger1Ref
94+
! TODO fir.call @_FortranAReduceInteger1Value
6795

6896
pure function red_int2(a,b)
6997
integer(2), intent(in) :: a, b

0 commit comments

Comments
 (0)