aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorergawy <kareem.ergawy@amd.com>2026-02-05 02:52:47 -0600
committerergawy <kareem.ergawy@amd.com>2026-02-05 02:52:47 -0600
commit001238c944f6e1a0361b76b39ef619480fc56428 (patch)
treeca84f1514909e76cbe0cd294421cb5e3a1158b1d
parent58912f3c73f9001b2495e1a801275cd537a9f4a9 (diff)
downloadllvm-users/ergawy/implicit_maps_declare_mapper.zip
llvm-users/ergawy/implicit_maps_declare_mapper.tar.gz
llvm-users/ergawy/implicit_maps_declare_mapper.tar.bz2
[flang][OpenMP] Attach compiler-emitted mappers to arrays of recordsusers/ergawy/implicit_maps_declare_mapper
Extends support for compiler-defined declare mappers for records. This fixes a bug where arrays of records that have allocatable fields were mapped incorrectly.
-rw-r--r--flang/lib/Lower/OpenMP/OpenMP.cpp3
-rw-r--r--flang/test/Lower/OpenMP/declare-mapper.f9029
2 files changed, 31 insertions, 1 deletions
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index df89cbe..614233d 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2784,7 +2784,8 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
if (!mapperIdName.empty()) {
bool allowImplicitMapper =
- semantics::IsAllocatableOrObjectPointer(&sym);
+ semantics::IsAllocatableOrObjectPointer(&sym) ||
+ requiresImplicitDefaultDeclareMapper(*typeSpec);
bool hasDefaultMapper =
converter.getModuleOp().lookupSymbol(mapperIdName);
if (hasDefaultMapper || allowImplicitMapper) {
diff --git a/flang/test/Lower/OpenMP/declare-mapper.f90 b/flang/test/Lower/OpenMP/declare-mapper.f90
index 7eda1a4..6708872 100644
--- a/flang/test/Lower/OpenMP/declare-mapper.f90
+++ b/flang/test/Lower/OpenMP/declare-mapper.f90
@@ -11,6 +11,7 @@
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-7.use.f90 -o - | FileCheck %t/omp-declare-mapper-7.use.f90
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -module-dir %t %t/omp-declare-mapper-8.mod.f90 -o - >/dev/null
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-8.use.f90 -o - | FileCheck %t/omp-declare-mapper-8.use.f90
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -J %t %t/omp-declare-mapper-9.implicit.f90 -o - | FileCheck %t/omp-declare-mapper-9.implicit.f90
!--- omp-declare-mapper-1.f90
subroutine declare_mapper_1
@@ -360,3 +361,31 @@ program use_module_default_mapper
a%x = 8
!$omp end target
end program use_module_default_mapper
+
+!--- omp-declare-mapper-9.implicit.f90
+! Verify that we emit declare mapper ops for arrays of records that are mapped
+! implicitly.
+
+! CHECK: omp.declare_mapper @[[MAPPER_NAME:.*record_with_alloc_modrecord_with_alloc_omp_default_mapper]] : !fir.type
+
+! CHECK: func.func @{{.*}}random_inputs()
+! CHECK: %[[ARR_DECL:.*]]:2 = hlfir.declare {{.*}} {{{.*}}, uniq_name = "{{.*}}inputs"}
+! CHECK: omp.map.info var_ptr(%[[ARR_DECL]]#1 : {{.*}}) {{.*}} mapper(@[[MAPPER_NAME]])
+! CHECK-NOT: omp.map.info
+module record_with_alloc_mod
+ implicit none
+ public :: record_with_alloc
+
+ type record_with_alloc
+ real, allocatable :: values_(:)
+ end type
+end module record_with_alloc_mod
+
+subroutine random_inputs()
+ use record_with_alloc_mod, only : record_with_alloc
+ type(record_with_alloc), target :: inputs(2)
+
+ !$omp target
+ inputs(1)%values_ = [1,2,3,4]
+ !$omp end target
+end subroutine