[flang-commits] [flang] [Flang][OpenMP][MLIR] Add attach and ref map type lowering to MLIR (PR #177301)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 29 10:51:07 PST 2026


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

>From 1b8a91b81327834b6b5adabd5da33e29a0f4428e Mon Sep 17 00:00:00 2001
From: agozillon <Andrew.Gozillon at amd.com>
Date: Tue, 20 Jan 2026 21:13:27 -0600
Subject: [PATCH] [Flang][OpenMP][MLIR] Add attach and ref map type lowering to
 MLIR

This doesn't implement the functionality, just the relevant map type
lowering to MLIR's omp.map.info. The more complicated changes to
MapInfoFinalizationPass.cpp and OpenMPTOLLVMIRTranslation.cpp to support
attach map and the various ref/attach semantics will come in a subsequent
set of PRs. This just helps compartmentalize the changeset.
---
 flang/lib/Lower/OpenMP/ClauseProcessor.cpp    | 31 ++++++++-
 .../Lower/OpenMP/Todo/attach-modifier.f90     |  9 ---
 .../Lower/OpenMP/attach-and-ref-modifier.f90  | 63 +++++++++++++++++++
 3 files changed, 92 insertions(+), 11 deletions(-)
 delete mode 100644 flang/test/Lower/OpenMP/Todo/attach-modifier.f90
 create mode 100644 flang/test/Lower/OpenMP/attach-and-ref-modifier.f90

diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 8094c6264b492..9e384b4959606 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -1475,8 +1475,7 @@ bool ClauseProcessor::processMap(
     mlir::Location clauseLocation = converter.genLocation(source);
     const auto &[mapType, typeMods, attachMod, refMod, mappers, iterator,
                  objects] = clause.t;
-    if (attachMod)
-      TODO(currentLocation, "ATTACH modifier is not implemented yet");
+
     mlir::omp::ClauseMapFlags mapTypeBits = mlir::omp::ClauseMapFlags::none;
     std::string mapperIdName = "__implicit_mapper";
     // If the map type is specified, then process it else set the appropriate
@@ -1521,6 +1520,34 @@ bool ClauseProcessor::processMap(
         mapTypeBits |= mlir::omp::ClauseMapFlags::ompx_hold;
     }
 
+    if (refMod) {
+      switch (*refMod) {
+      case Map::RefModifier::RefPtee:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::ref_ptee;
+        break;
+      case Map::RefModifier::RefPtr:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::ref_ptr;
+        break;
+      case Map::RefModifier::RefPtrPtee:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::ref_ptr_ptee;
+        break;
+      }
+    }
+
+    if (attachMod) {
+      switch (*attachMod) {
+      case Map::AttachModifier::Always:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::attach_always;
+        break;
+      case Map::AttachModifier::Never:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::attach_never;
+        break;
+      case Map::AttachModifier::Auto:
+        mapTypeBits |= mlir::omp::ClauseMapFlags::attach_auto;
+        break;
+      }
+    }
+
     if (iterator) {
       TODO(currentLocation,
            "Support for iterator modifiers is not implemented yet");
diff --git a/flang/test/Lower/OpenMP/Todo/attach-modifier.f90 b/flang/test/Lower/OpenMP/Todo/attach-modifier.f90
deleted file mode 100644
index 099f4a4d8255c..0000000000000
--- a/flang/test/Lower/OpenMP/Todo/attach-modifier.f90
+++ /dev/null
@@ -1,9 +0,0 @@
-!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=61 -o - %s 2>&1 | FileCheck %s
-!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=61 -o - %s 2>&1 | FileCheck %s
-
-!CHECK: not yet implemented: ATTACH modifier is not implemented yet
-subroutine f00(x)
-  integer, pointer :: x
-  !$omp target map(attach(always), tofrom: x)
-  !$omp end target
-end
diff --git a/flang/test/Lower/OpenMP/attach-and-ref-modifier.f90 b/flang/test/Lower/OpenMP/attach-and-ref-modifier.f90
new file mode 100644
index 0000000000000..279425ee9f9b3
--- /dev/null
+++ b/flang/test/Lower/OpenMP/attach-and-ref-modifier.f90
@@ -0,0 +1,63 @@
+! RUN: %flang_fc1 -fopenmp -fopenmp-version=61 -emit-hlfir %s -o - 2>&1 | FileCheck %s
+
+subroutine attach_always()
+    integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(tofrom, attach_always){{.*}}
+    !$omp target map(attach(always): x)
+        x = 1
+    !$omp end target
+end
+
+subroutine attach_never()
+    integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(tofrom, attach_never){{.*}}
+    !$omp target map(attach(never): x)
+        x = 1
+    !$omp end target
+end
+
+subroutine attach_auto()
+    integer, pointer :: x
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(tofrom, attach_auto){{.*}}
+    !$omp target map(attach(auto): x)
+        x = 1
+    !$omp end target
+end
+
+subroutine ref_ptr_ptee()
+    integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(to, ref_ptr_ptee){{.*}}
+    !$omp target map(ref_ptr_ptee, to: x)
+        x = 1
+    !$omp end target
+end
+
+subroutine ref_ptr()
+  integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(to, ref_ptr){{.*}}
+    !$omp target map(ref_ptr, to: x)
+        x = 1
+    !$omp end target
+end
+
+subroutine ref_ptee()
+  integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(to, ref_ptee){{.*}}
+    !$omp target map(ref_ptee, to: x)
+        x = 1
+    !$omp end target
+end
+
+subroutine ref_ptr_ptee_attach_never()
+    integer, pointer :: x
+
+!CHECK: {{.*}} = omp.map.info{{.*}}map_clauses(to, attach_never, ref_ptr_ptee){{.*}}
+    !$omp target map(attach(never), ref_ptr_ptee, to: x)
+        x = 1
+    !$omp end target
+end



More information about the flang-commits mailing list