[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread via cfe-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/228748

>From 83586e75ff7e6394331cce76e548011bd8d2bb55 Mon Sep 17 00:00:00 2001
From: agozillon 
Date: Fri, 2 Oct 2026 06:45:12 -0500
Subject: [PATCH 1/3] [Flang][OpenMP] Flag for switching off implicit
 allocatable member mapping via default declare mapper

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types.
However, it is quite an expensive overhead to perform implicit allocatable 
member mapping as it
requires a mapper to do so due to the nature of possibly nested allocatable 
derived types etc.
Alongside a fairly comprehensive map of the record, this in particular comes at 
a fairly substantial
cost for arrays of derived types that trigger this behaviour. Some of this may 
or may not be
mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray
in particular I think) and utilise a flag that can switch this behaviour on and 
off, so that
applications not depending on the crutch of this implicit mapping can deactivte 
it and not pay
the overhead, and those that like the compiler to do this for them can continue 
to do so.
---
 clang/include/clang/Options/FlangOptions.td   |  6 ++
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/include/flang/Support/Flags.h   |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  5 ++
 flang/lib/Frontend/FrontendActions.cpp|  6 ++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  4 +-
 flang/lib/Lower/OpenMP/Utils.cpp  | 13 ++-
 flang/lib/Lower/OpenMP/Utils.h|  3 +-
 flang/lib/Support/Flags.cpp   |  6 ++
 flang/test/Driver/omp-driver-offload.f90  | 41 ++
 ...efault-mapper-allocatable-members-flag.f90 | 81 +++
 12 files changed, 172 insertions(+), 5 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index b07a6bdd1e606a..ad39d052bee6af 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -317,6 +317,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Disable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+
+
 def J : JoinedOrSeparate<["-"], "J">,
   Flags<[RenderJoined]>, Group, Alias;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 94b092e711be64..08ac0e8fd8e190 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -880,6 +880,16 @@ void Flang::addOffloadOptions(Compilation &C, const 
InputInfoList &Inputs,
/*Default=*/false))
 CmdArgs.push_back("-fopenmp-assume-threads-oversubscription");
 
+  // This forwards the option to switch off/on mapper generation for scenarios
+  // where the compiler considers it neccessary to generate a mapper to cover
+  // implicit allocatable member mapping inside of derived types to adhere to
+  // specification compliance.
+  if (!Args.hasFlag(
+  options::OPT_fimplicit_default_mapper_allocatable_members,
+  options::OPT_fno_implicit_default_mapper_allocatable_members,
+  /*Default=*/true))
+CmdArgs.push_back("-fno-implicit-default-mapper-allocatable-members");
+
   if (IsOpenMPDevice) {
 // -fopenmp-is-target-device is passed along to tell the frontend that it 
is
 // generating code for a device, so that only the relevant code is emitted.
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 569a6aa289ca31..bae78887f4ce09 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -63,6 +63,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread Akash Banerjee via cfe-commits


@@ -76,7 +77,13 @@ namespace Fortran {
 namespace lower {
 namespace omp {
 bool requiresImplicitDefaultDeclareMapper(
-const semantics::DerivedTypeSpec &typeSpec) {
+const semantics::DerivedTypeSpec &typeSpec,
+bool enableImplicitDefaultMapperAllocatableMembers) {
+  // If disabled via -fno-implicit-default-mapper-allocatable-members
+  // return false, as we do not need to emit allocatable member maps.
+  if (!enableImplicitDefaultMapperAllocatableMembers)

TIFitis wrote:

Sorry that this turned out to be a pre-existing bug.

Thank you for still working on a fix, and number 2 looks reasonable to me. 

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread Akash Banerjee via cfe-commits


@@ -317,6 +318,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,

TIFitis wrote:

With `-fdo-concurrent-to-openmp=device`, the disabling flag still generates an 
implicit default mappers. I think we need to propagate this flag to DO 
CONCURRENT conversion so the opt-out flag works there too.

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread via cfe-commits


@@ -76,7 +77,13 @@ namespace Fortran {
 namespace lower {
 namespace omp {
 bool requiresImplicitDefaultDeclareMapper(
-const semantics::DerivedTypeSpec &typeSpec) {
+const semantics::DerivedTypeSpec &typeSpec,
+bool enableImplicitDefaultMapperAllocatableMembers) {
+  // If disabled via -fno-implicit-default-mapper-allocatable-members
+  // return false, as we do not need to emit allocatable member maps.
+  if (!enableImplicitDefaultMapperAllocatableMembers)

agozillon wrote:

Last commit should I think handle both cases via number 2. I did have a little 
look at 1 but I think that's definitely something for a larger follow up patch, 
it'd need a bit of thinking to avoid extra maps by attaching a mapper to a 
member and then having another mapper already cover that case, so effectively 
doing the same map twice.

TL;DR: I think I handle the case now, I've added a few new tests to try and 
verify it does what we wish. 

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread via cfe-commits


@@ -76,7 +77,13 @@ namespace Fortran {
 namespace lower {
 namespace omp {
 bool requiresImplicitDefaultDeclareMapper(
-const semantics::DerivedTypeSpec &typeSpec) {
+const semantics::DerivedTypeSpec &typeSpec,
+bool enableImplicitDefaultMapperAllocatableMembers) {
+  // If disabled via -fno-implicit-default-mapper-allocatable-members
+  // return false, as we do not need to emit allocatable member maps.
+  if (!enableImplicitDefaultMapperAllocatableMembers)

agozillon wrote:

So, this one is an odd one that I am not entirely sure should be handled in 
this PR, but I'll update it none the less and we can discuss fracturing it into 
a separate commit if it doesn't make sense. 

That case seems to only work because there's an allocatable member inside of 
outer, if you remove it or change it to a non-allocatable, you run into the 
exact same problem with/without this patch. So this allocatable case is 
effectively an oddity and is being propped up entirely by the implicit 
allocatable mapper behaviour.

There's two options I can see and I'll likely opt for the path of least 
resistance for now which would be number 2:

1) We generate a member map that we can attach the mapper to, rather than 
recursively creating mappers. As a recursive series of mappers just for a 
nested user mapper feels a bit overkill. But that works entirely differently to 
how it does today for this example, hence option 2.
2) We generate our usual nested mappers if we find a need to (user defined 
mapper in nesting), but opt out of emitting allocatable maps for the mappers we 
create along the way.

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread Akash Banerjee via cfe-commits


@@ -317,6 +318,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,

TIFitis wrote:

That makes sense, thanks for clearing this.

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-11-02 Thread via cfe-commits


@@ -317,6 +318,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,

agozillon wrote:

While it does use the same functionality, I don't think we want to inhibit this 
part of the compiler with this flag, primarily as do-concurrent is entirely 
contingent on having the implicit mapping behaviour to work at all reasonably, 
as there's no way to explicitly map anything in a do concurrent context (other 
than enter/exit maps, but I am not sure that's a common thing to do for the 
kind of applications that just want the extra parallelism on do concurrent) to 
actually map the allocatable bits to device for it, and realistically maybe it 
should also be doing so for pointers as I imagine they're not being mapped at 
the moment.

@pranavb-ca @mjklemm what are your opinions on this, I don't mind either way, I 
suppose it would allow users the ability to similarly opt out of allocatables 
being mapped in do concurrent if they know what they're doing

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-23 Thread via cfe-commits


@@ -230,3 +230,55 @@
 ! OFFLOAD-TARGETS-NOT: --offload-targets
 ! OFFLOAD-TARGETS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" 
"x86_64-unknown-linux-gnu"
 ! OFFLOAD-TARGETS-SAME: "--offload-targets=amdgpu-amd-amdhsa"
+
+! Verify the implicit default mapper allocatable members flags are applied to 
both host
+! and device phases of the offload compilation when the negative flag is used 
and ignored
+! in the positive case as it is the default.
+
+! RUN: %flang -### %s 2>&1 \
+! RUN: -fopenmp -fimplicit-default-mapper-allocatable-members 
--offload-arch=gfx90a \
+! RUN: --target=x86_64-unknown-linux-gnu -nogpulib \
+! RUN:   | FileCheck %s --check-prefix=ENABLE-IMP-MAPPER
+
+! ENABLE-IMP-MAPPER: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! ENABLE-IMP-MAPPER-SAME: "-fopenmp"
+! ENABLE-IMP-MAPPER-SAME: "--offload-targets=amdgpu-amd-amdhsa"
+! ENABLE-IMP-MAPPER-NOT: implicit-default-mapper-allocatable-members

agozillon wrote:

Thank you, you're correct! Sorry, too used to writing separate cases for 
everything.

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-23 Thread via cfe-commits

agozillon wrote:

> Sorry for being fussy, but ...

not at all, it's fine, important to get the PR to a state everyone is happy 
with  :-)

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-23 Thread via cfe-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/228748

>From 98df6adda4ac0d514bf0e10db6fd5a0d1bcc75af Mon Sep 17 00:00:00 2001
From: agozillon 
Date: Fri, 2 Oct 2026 06:45:12 -0500
Subject: [PATCH 1/2] [Flang][OpenMP] Flag for switching off implicit
 allocatable member mapping via default declare mapper

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types.
However, it is quite an expensive overhead to perform implicit allocatable 
member mapping as it
requires a mapper to do so due to the nature of possibly nested allocatable 
derived types etc.
Alongside a fairly comprehensive map of the record, this in particular comes at 
a fairly substantial
cost for arrays of derived types that trigger this behaviour. Some of this may 
or may not be
mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray
in particular I think) and utilise a flag that can switch this behaviour on and 
off, so that
applications not depending on the crutch of this implicit mapping can deactivte 
it and not pay
the overhead, and those that like the compiler to do this for them can continue 
to do so.
---
 clang/include/clang/Options/FlangOptions.td   |  6 ++
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/include/flang/Support/Flags.h   |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  5 ++
 flang/lib/Frontend/FrontendActions.cpp|  6 ++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  4 +-
 flang/lib/Lower/OpenMP/Utils.cpp  | 13 ++-
 flang/lib/Lower/OpenMP/Utils.h|  3 +-
 flang/lib/Support/Flags.cpp   |  6 ++
 flang/test/Driver/omp-driver-offload.f90  | 41 ++
 ...efault-mapper-allocatable-members-flag.f90 | 81 +++
 12 files changed, 172 insertions(+), 5 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 662360725afea0..7447ba458954f1 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -318,6 +318,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Disable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+
+
 def J : JoinedOrSeparate<["-"], "J">,
   Flags<[RenderJoined]>, Group, Alias;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 97d9dd1c501d99..97e181febf775b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -882,6 +882,16 @@ void Flang::addOffloadOptions(Compilation &C, const 
InputInfoList &Inputs,
/*Default=*/false))
 CmdArgs.push_back("-fopenmp-assume-threads-oversubscription");
 
+  // This forwards the option to switch off/on mapper generation for scenarios
+  // where the compiler considers it neccessary to generate a mapper to cover
+  // implicit allocatable member mapping inside of derived types to adhere to
+  // specification compliance.
+  if (!Args.hasFlag(
+  options::OPT_fimplicit_default_mapper_allocatable_members,
+  options::OPT_fno_implicit_default_mapper_allocatable_members,
+  /*Default=*/true))
+CmdArgs.push_back("-fno-implicit-default-mapper-allocatable-members");
+
   if (IsOpenMPDevice) {
 // -fopenmp-is-target-device is passed along to tell the frontend that it 
is
 // generating code for a device, so that only the relevant code is emitted.
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 569a6aa289ca31..bae78887f4ce09 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -63,6 +63,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-23 Thread via cfe-commits

agozillon wrote:

Updated the test to share same CHECK lines!

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-22 Thread via cfe-commits




agozillon wrote:

It's not uncommon but not a requirement either, I can certainly split it into 
two separate tests :-)

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-20 Thread via cfe-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/228748

>From 10a4a8a8721ed213a2a7662eca5863f41f5de444 Mon Sep 17 00:00:00 2001
From: agozillon 
Date: Fri, 2 Oct 2026 06:45:12 -0500
Subject: [PATCH] [Flang][OpenMP] Flag for switching off implicit allocatable
 member mapping via default declare mapper

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types.
However, it is quite an expensive overhead to perform implicit allocatable 
member mapping as it
requires a mapper to do so due to the nature of possibly nested allocatable 
derived types etc.
Alongside a fairly comprehensive map of the record, this in particular comes at 
a fairly substantial
cost for arrays of derived types that trigger this behaviour. Some of this may 
or may not be
mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray
in particular I think) and utilise a flag that can switch this behaviour on and 
off, so that
applications not depending on the crutch of this implicit mapping can deactivte 
it and not pay
the overhead, and those that like the compiler to do this for them can continue 
to do so.
---
 clang/include/clang/Options/FlangOptions.td   |  6 ++
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/include/flang/Support/Flags.h   |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  5 ++
 flang/lib/Frontend/FrontendActions.cpp|  6 ++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  4 +-
 flang/lib/Lower/OpenMP/Utils.cpp  | 13 ++-
 flang/lib/Lower/OpenMP/Utils.h|  3 +-
 flang/lib/Support/Flags.cpp   |  6 ++
 flang/test/Driver/omp-driver-offload.f90  | 38 +
 ...efault-mapper-allocatable-members-flag.f90 | 81 +++
 12 files changed, 169 insertions(+), 5 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 2844ee854a120..71e61e94e3977 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -314,6 +314,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Disable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+
+
 def J : JoinedOrSeparate<["-"], "J">,
   Flags<[RenderJoined]>, Group, Alias;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index a13c69a5b2a50..3a47333ab0e84 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -876,6 +876,16 @@ void Flang::addOffloadOptions(Compilation &C, const 
InputInfoList &Inputs,
/*Default=*/false))
 CmdArgs.push_back("-fopenmp-assume-threads-oversubscription");
 
+  // This forwards the option to switch off/on mapper generation for scenarios
+  // where the compiler considers it neccessary to generate a mapper to cover
+  // implicit allocatable member mapping inside of derived types to adhere to
+  // specification compliance.
+  if (!Args.hasFlag(
+  options::OPT_fimplicit_default_mapper_allocatable_members,
+  options::OPT_fno_implicit_default_mapper_allocatable_members,
+  /*Default=*/true))
+CmdArgs.push_back("-fno-implicit-default-mapper-allocatable-members");
+
   if (IsOpenMPDevice) {
 // -fopenmp-is-target-device is passed along to tell the frontend that it 
is
 // generating code for a device, so that only the relevant code is emitted.
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 86994f7710576..92d6e44b2af5b 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -62,6 +62,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread via cfe-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/228748

>From e714a775a97456f1be2d71d11f18365379b53390 Mon Sep 17 00:00:00 2001
From: agozillon 
Date: Fri, 2 Oct 2026 06:45:12 -0500
Subject: [PATCH] [Flang][OpenMP] Flag for switching off implicit allocatable
 member mapping via default declare mapper

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types.
However, it is quite an expensive overhead to perform implicit allocatable 
member mapping as it
requires a mapper to do so due to the nature of possibly nested allocatable 
derived types etc.
Alongside a fairly comprehensive map of the record, this in particular comes at 
a fairly substantial
cost for arrays of derived types that trigger this behaviour. Some of this may 
or may not be
mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray
in particular I think) and utilise a flag that can switch this behaviour on and 
off, so that
applications not depending on the crutch of this implicit mapping can deactivte 
it and not pay
the overhead, and those that like the compiler to do this for them can continue 
to do so.
---
 clang/include/clang/Options/FlangOptions.td   |  6 ++
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/include/flang/Support/Flags.h   |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  5 ++
 flang/lib/Frontend/FrontendActions.cpp|  6 ++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  4 +-
 flang/lib/Lower/OpenMP/Utils.cpp  | 13 ++-
 flang/lib/Lower/OpenMP/Utils.h|  3 +-
 flang/lib/Support/Flags.cpp   |  6 ++
 flang/test/Driver/omp-driver-offload.f90  | 38 +
 ...efault-mapper-allocatable-members-flag.f90 | 81 +++
 12 files changed, 169 insertions(+), 5 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 5a45528a39a6d..cd6ab4879e15a 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -312,6 +312,12 @@ def fdo_concurrent_to_openmp_EQ : Joined<["-"], 
"fdo-concurrent-to-openmp=">,
   HelpText<"Try to map `do concurrent` loops to OpenMP [none|host|device]">,
   Values<"none, host, device">;
 
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Enable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, HelpText<"Disable implicit allocatable member maps in 
compiler-generated OpenMP default mappers">;
+
+
 def J : JoinedOrSeparate<["-"], "J">,
   Flags<[RenderJoined]>, Group, Alias;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 37d0372e7a18e..7e8eb97a2eeb5 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -874,6 +874,16 @@ void Flang::addOffloadOptions(Compilation &C, const 
InputInfoList &Inputs,
/*Default=*/false))
 CmdArgs.push_back("-fopenmp-assume-threads-oversubscription");
 
+  // This forwards the option to switch off/on mapper generation for scenarios
+  // where the compiler considers it neccessary to generate a mapper to cover
+  // implicit allocatable member mapping inside of derived types to adhere to
+  // specification compliance.
+  if (!Args.hasFlag(
+  options::OPT_fimplicit_default_mapper_allocatable_members,
+  options::OPT_fno_implicit_default_mapper_allocatable_members,
+  /*Default=*/true))
+CmdArgs.push_back("-fno-implicit-default-mapper-allocatable-members");
+
   if (IsOpenMPDevice) {
 // -fopenmp-is-target-device is passed along to tell the frontend that it 
is
 // generating code for a device, so that only the relevant code is emitted.
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 86994f7710576..92d6e44b2af5b 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -62,6 +62,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits


@@ -386,6 +386,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
options::OPT_ftime_report, options::OPT_ftime_report_EQ,
options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
+   options::OPT_fimplicit_default_mapper_allocatable_members,
+   options::OPT_fno_implicit_default_mapper_allocatable_members,

tarunprabhu wrote:

Instead of passing these unconditionally, I would suggest only passing the 
"winner" to `-fc1`. This will be the last occurrence of 
`-f(no)-implicit-default-mapper-allocatable-members`. This could be done by 
adding the following to `addOffloadOptions`. 

```
if (!Args.hasFlag(options::OPT_fimplicit_default_mapper_allocatable_members,
   options::OPT_fno_implicit_default_mapper_allocatable_members,
   /*Default=*/true))
CmdArgs.push_back("-fno-implicit-default-mapper-allocatable-members");
```

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits


@@ -72,6 +72,12 @@ defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, 
Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Enable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Disable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;

tarunprabhu wrote:

I would suggest moving these declarations into the "visibility block" below 
(around line 172)

```
let Visibility = [FC1Option, FlangOption] in {
```

It is a more appropriate place for them, and you can also leave off the 
`Visibility` specification if you do so.

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu requested changes to this pull request.

Please add tests for the driver as well. These should generally check that the 
correct default is passed to `-fc1`, and that, when multiple instances of 
`-f(no)-implicit-default-mapper-allocatable-members` are passed, the last one 
"wins".

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu edited 
https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits


@@ -560,6 +560,11 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
 opts.Underscoring = 0;
   }
 
+  opts.ImplicitDefaultMapperAllocatableMembers = args.hasFlag(
+  clang::options::OPT_fimplicit_default_mapper_allocatable_members,
+  clang::options::OPT_fno_implicit_default_mapper_allocatable_members,
+  true);

tarunprabhu wrote:

```suggestion
  /*Default=*/true);
```

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-05 Thread Tarun Prabhu via cfe-commits


@@ -13,5 +13,6 @@
 
 extern llvm::cl::opt enableDelayedPrivatization;
 extern llvm::cl::opt enableDelayedPrivatizationStaging;
+extern bool enableImplicitDefaultMapperAllocatableMembers;

tarunprabhu wrote:

I am not very familiar with the OpenMP implementation in flang, but is there 
really no other way to pass a flag down to it other than this? It feels a bit 
fragile to me. @tblah, do you have any suggestions on alternative ways of doing 
this?

https://github.com/llvm/llvm-project/pull/228748
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-03 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: agozillon


Changes

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types. However, it is quite an expensive overhead to perform 
implicit allocatable member mapping as it requires a mapper to do so due to the 
nature of possibly nested allocatable derived types etc. Alongside a fairly 
comprehensive map of the record, this in particular comes at a fairly 
substantial cost for arrays of derived types that trigger this behaviour. Some 
of this may or may not be mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray in particular I think) and utilise a flag that can switch this 
behaviour on and off, so that applications not depending on the crutch of this 
implicit mapping can deactivte it and not pay the overhead, and those that like 
the compiler to do this for them can continue to do so.

---
Full diff: https://github.com/llvm/llvm-project/pull/228748.diff


11 Files Affected:

- (modified) clang/include/clang/Options/FlangOptions.td (+6) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.def (+1) 
- (modified) flang/include/flang/Support/Flags.h (+1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+5) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+6) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+3-1) 
- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+10-3) 
- (modified) flang/lib/Lower/OpenMP/Utils.h (+2-1) 
- (modified) flang/lib/Support/Flags.cpp (+2) 
- (added) 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90 
(+81) 


``diff
diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 5a45528a39a6d5..d078e936b6647a 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -72,6 +72,12 @@ defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, 
Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Enable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Disable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 37d0372e7a18ed..c7e3552c019a1e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -386,6 +386,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
options::OPT_ftime_report, options::OPT_ftime_report_EQ,
options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
+   options::OPT_fimplicit_default_mapper_allocatable_members,
+   options::OPT_fno_implicit_default_mapper_allocatable_members,
options::OPT_relaxed_c_loc});
 
   Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 86994f7710576c..92d6e44b2af5bf 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -62,6 +62,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 CODEGENOPT(Underscoring, 1, 1)
 ENUM_CODEGENOPT(FPMaxminBehavior, Fortran::common::FPMaxminBehavior, 2, 
Fortran::common::FPMaxminBehavior::Legacy)
diff --git a/flang/include/flang/Support/Flags.h 
b/flang/include/flang/Support/Flags.h
index bcbb72f8e50d05..2e139b50cdc332 100644
--- a/flang/include/flang/Support/Flags.h
+++ b/flang/include/flang/Support/Flags.h
@@ -13,5 +13,6 @@
 
 extern llvm::cl::opt enableDelayedPrivatization;
 extern llvm::cl::opt enableDelayedPrivatizationStaging;
+extern bool enableImplicitDefaultMapperAllocatableMembers;
 
 #endif 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-03 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-flang-driver

Author: agozillon


Changes

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types. However, it is quite an expensive overhead to perform 
implicit allocatable member mapping as it requires a mapper to do so due to the 
nature of possibly nested allocatable derived types etc. Alongside a fairly 
comprehensive map of the record, this in particular comes at a fairly 
substantial cost for arrays of derived types that trigger this behaviour. Some 
of this may or may not be mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray in particular I think) and utilise a flag that can switch this 
behaviour on and off, so that applications not depending on the crutch of this 
implicit mapping can deactivte it and not pay the overhead, and those that like 
the compiler to do this for them can continue to do so.

---
Full diff: https://github.com/llvm/llvm-project/pull/228748.diff


11 Files Affected:

- (modified) clang/include/clang/Options/FlangOptions.td (+6) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.def (+1) 
- (modified) flang/include/flang/Support/Flags.h (+1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+5) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+6) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+3-1) 
- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+10-3) 
- (modified) flang/lib/Lower/OpenMP/Utils.h (+2-1) 
- (modified) flang/lib/Support/Flags.cpp (+2) 
- (added) 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90 
(+81) 


``diff
diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 5a45528a39a6d5..d078e936b6647a 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -72,6 +72,12 @@ defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, 
Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Enable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Disable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 37d0372e7a18ed..c7e3552c019a1e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -386,6 +386,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
options::OPT_ftime_report, options::OPT_ftime_report_EQ,
options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
+   options::OPT_fimplicit_default_mapper_allocatable_members,
+   options::OPT_fno_implicit_default_mapper_allocatable_members,
options::OPT_relaxed_c_loc});
 
   Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 86994f7710576c..92d6e44b2af5bf 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -62,6 +62,7 @@ CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
 CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
+CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
 
 CODEGENOPT(Underscoring, 1, 1)
 ENUM_CODEGENOPT(FPMaxminBehavior, Fortran::common::FPMaxminBehavior, 2, 
Fortran::common::FPMaxminBehavior::Legacy)
diff --git a/flang/include/flang/Support/Flags.h 
b/flang/include/flang/Support/Flags.h
index bcbb72f8e50d05..2e139b50cdc332 100644
--- a/flang/include/flang/Support/Flags.h
+++ b/flang/include/flang/Support/Flags.h
@@ -13,5 +13,6 @@
 
 extern llvm::cl::opt enableDelayedPrivatization;
 extern llvm::cl::opt enableDelayedPrivatizationStaging;
+extern bool enableImplicitDefaultMapperAllocatableMembers;
 
 #endif // 

[clang] [flang] [Flang][OpenMP] Flag for switching off implicit allocatable member mapping via default declare mapper (PR #228748)

2026-10-03 Thread via cfe-commits

https://github.com/agozillon created 
https://github.com/llvm/llvm-project/pull/228748

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types. However, it is quite an expensive overhead to perform 
implicit allocatable member mapping as it requires a mapper to do so due to the 
nature of possibly nested allocatable derived types etc. Alongside a fairly 
comprehensive map of the record, this in particular comes at a fairly 
substantial cost for arrays of derived types that trigger this behaviour. Some 
of this may or may not be mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray in particular I think) and utilise a flag that can switch this 
behaviour on and off, so that applications not depending on the crutch of this 
implicit mapping can deactivte it and not pay the overhead, and those that like 
the compiler to do this for them can continue to do so.

>From bce7219bb458d4cdd816e729f1871c705b5414f4 Mon Sep 17 00:00:00 2001
From: agozillon 
Date: Fri, 2 Oct 2026 06:45:12 -0500
Subject: [PATCH] [Flang][OpenMP] Flag for switching off implicit allocatable
 member mapping via default declare mapper

Part of the OpenMP specification requires implicitly mappiing allocatable 
members in derived types.
However, it is quite an expensive overhead to perform implicit allocatable 
member mapping as it
requires a mapper to do so due to the nature of possibly nested allocatable 
derived types etc.
Alongside a fairly comprehensive map of the record, this in particular comes at 
a fairly substantial
cost for arrays of derived types that trigger this behaviour. Some of this may 
or may not be
mitigatable over time.

But for the moment this PR seeks to follow the example of other Fortran OpenMP 
compilers (Cray
in particular I think) and utilise a flag that can switch this behaviour on and 
off, so that
applications not depending on the crutch of this implicit mapping can deactivte 
it and not pay
the overhead, and those that like the compiler to do this for them can continue 
to do so.
---
 clang/include/clang/Options/FlangOptions.td   |  6 ++
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/include/flang/Support/Flags.h   |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  5 ++
 flang/lib/Frontend/FrontendActions.cpp|  6 ++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  4 +-
 flang/lib/Lower/OpenMP/Utils.cpp  | 13 ++-
 flang/lib/Lower/OpenMP/Utils.h|  3 +-
 flang/lib/Support/Flags.cpp   |  2 +
 ...efault-mapper-allocatable-members-flag.f90 | 81 +++
 11 files changed, 119 insertions(+), 5 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/implicit-default-mapper-allocatable-members-flag.f90

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 5a45528a39a6d5e..d078e936b6647a1 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -72,6 +72,12 @@ defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, 
Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
+def fimplicit_default_mapper_allocatable_members : Flag<["-"], 
"fimplicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Enable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
+def fno_implicit_default_mapper_allocatable_members : Flag<["-"], 
"fno-implicit-default-mapper-allocatable-members">,
+  Group, Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Disable implicit allocatable member maps in compiler-generated 
OpenMP default mappers">;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 37d0372e7a18ed7..c7e3552c019a1e8 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -386,6 +386,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
options::OPT_ftime_report, options::OPT_ftime_report_EQ,
options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
+   options::OPT_fimplicit_default_mapper_allocatable_members,
+   options::OPT_fno_implicit_default_mapper_allocatable_members,
options::OPT_relaxed_c_loc});
 
   Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 86994f7710576c0..92d6e44b2af5bf9 100644
---