Skip to content

Commit 7b074fc

Browse files
authored
[flang][openacc] Allow polymorphic entity in data clauses (#141856)
- Attach the mappable interface to ClassType - Remove the TODO since derived type in descriptor can be handled as other descriptors
1 parent cf3201c commit 7b074fc

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

flang/include/flang/Optimizer/Builder/DirectivesCommon.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ inline AddrAndBoundsInfo getDataOperandBaseAddr(fir::FirOpBuilder &builder,
7575

7676
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(
7777
fir::unwrapRefType(symAddr.getType()))) {
78-
if (mlir::isa<fir::RecordType>(boxTy.getEleTy()))
79-
TODO(loc, "derived type");
80-
8178
// In case of a box reference, load it here to get the box value.
8279
// This is preferrable because then the same box value can then be used for
8380
// all address/dimension retrievals. For Fortran optional though, leave

flang/lib/Optimizer/OpenACC/RegisterOpenACCExtensions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void registerOpenACCExtensions(mlir::DialectRegistry &registry) {
2222
fir::SequenceType::attachInterface<OpenACCMappableModel<fir::SequenceType>>(
2323
*ctx);
2424
fir::BoxType::attachInterface<OpenACCMappableModel<fir::BaseBoxType>>(*ctx);
25+
fir::ClassType::attachInterface<OpenACCMappableModel<fir::BaseBoxType>>(
26+
*ctx);
2527

2628
fir::ReferenceType::attachInterface<
2729
OpenACCPointerLikeModel<fir::ReferenceType>>(*ctx);

flang/test/Lower/OpenACC/acc-enter-data.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
44

5+
module mod1
6+
implicit none
7+
type :: derived
8+
real :: m
9+
contains
10+
end type derived
11+
end module mod1
12+
513
subroutine acc_enter_data
614
integer :: async = 1
715
real, dimension(10, 10) :: a, b, c
@@ -651,3 +659,15 @@ subroutine acc_enter_data_single_array_element()
651659
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.heap<!fir.array<?x?xf32>>)
652660

653661
end subroutine
662+
663+
subroutine test_class(a)
664+
use mod1
665+
class(derived) :: a
666+
!$acc enter data copyin(a)
667+
end subroutine
668+
669+
! CHECK-LABEL: func.func @_QPtest_class(
670+
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMmod1Tderived{m:f32}>> {fir.bindc_name = "a"}) {
671+
! CHECK: %[[DECL_ARG0:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %0 {uniq_name = "_QFtest_classEa"} : (!fir.class<!fir.type<_QMmod1Tderived{m:f32}>>, !fir.dscope) -> (!fir.class<!fir.type<_QMmod1Tderived{m:f32}>>, !fir.class<!fir.type<_QMmod1Tderived{m:f32}>>)
672+
! CHECK: %[[COPYIN:.*]] = acc.copyin var(%[[DECL_ARG0]]#0 : !fir.class<!fir.type<_QMmod1Tderived{m:f32}>>) -> !fir.class<!fir.type<_QMmod1Tderived{m:f32}>> {name = "a", structured = false}
673+
! CHECK: acc.enter_data dataOperands(%[[COPYIN]] : !fir.class<!fir.type<_QMmod1Tderived{m:f32}>>)

0 commit comments

Comments
 (0)