[flang-commits] [flang] [flang][mlir] Add flang to mlir lowering for groupprivate (PR #180934)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Jun 8 08:25:28 PDT 2026


================
@@ -408,6 +408,30 @@ static void PutOpenMPDeclarativeDirectives(llvm::raw_ostream &os,
         decls->printClauseSet(os, dtgt, symbol.name());
         os << "\n";
       }
+      // Re-emit `!$omp groupprivate` (and any recorded device_type) so a TU
+      // that `use`s this module recovers the directive from the .mod file.
+      // Common-block names must be wrapped in slashes when reparsed.
+      if (symbol.test(Symbol::Flag::OmpGroupPrivate)) {
+        os << "!$omp groupprivate(";
+        if (symbol.detailsIf<CommonBlockDetails>())
+          os << '/' << symbol.name() << '/';
+        else
+          os << symbol.name();
+        os << ")";
+        if (auto deviceType{decls->ompGroupprivateDeviceType()}) {
+          switch (*deviceType) {
+          case common::OmpDeviceType::Any:
+            break;
+          case common::OmpDeviceType::Host:
+            os << " device_type(host)";
+            break;
+          case common::OmpDeviceType::Nohost:
+            os << " device_type(nohost)";
+            break;
+          }
----------------
skatrak wrote:

Related to a comment I'm making to symbol.h: Can this be handled with `decls->printClauseSet()` instead? It would have to be updated to handle the fact that both `declare_target` and `groupprivate` could hold information for the `device_type` clause, but otherwise this would make the handling more uniform.

We're currently also missing some changes to `llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const WithOmpDeclarative &x)` in flang/lib/Semantics/symbol.cpp to print the `groupprivate device_type`, but I think these changes would help do it the same way as for `declare_target`.

https://github.com/llvm/llvm-project/pull/180934


More information about the flang-commits mailing list