[flang-commits] [flang] [llvm] [flang][OpenMP] Try to unify induction var privatization for OMP regions. (PR #91116)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Tue May 14 08:53:58 PDT 2024


================
@@ -330,25 +353,46 @@ void DataSharingProcessor::collectSymbols(
   converter.collectSymbolSet(eval, allSymbols, flag,
                              /*collectSymbols=*/true,
                              /*collectHostAssociatedSymbols=*/true);
+
   llvm::SetVector<const Fortran::semantics::Symbol *> symbolsInNestedRegions;
   collectSymbolsInNestedRegions(eval, flag, symbolsInNestedRegions);
   // Filter-out symbols that must not be privatized.
   bool collectImplicit = flag == Fortran::semantics::Symbol::Flag::OmpImplicit;
+  bool collectPreDetermined =
+      flag == Fortran::semantics::Symbol::Flag::OmpPreDetermined;
+
   auto isPrivatizable = [](const Fortran::semantics::Symbol &sym) -> bool {
     return !Fortran::semantics::IsProcedure(sym) &&
            !sym.GetUltimate().has<Fortran::semantics::DerivedTypeDetails>() &&
            !sym.GetUltimate().has<Fortran::semantics::NamelistDetails>() &&
            !Fortran::semantics::IsImpliedDoIndex(sym.GetUltimate());
   };
+
+  auto shouldCollectSymbol = [&](const Fortran::semantics::Symbol *sym) {
+    if (collectImplicit &&
+        sym->test(Fortran::semantics::Symbol::Flag::OmpImplicit) &&
+        !sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined))
+      return true;
+
+    if (collectPreDetermined &&
+        sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined))
+      return true;
+
+    if (!sym->test(Fortran::semantics::Symbol::Flag::OmpImplicit) &&
+        !sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined))
+      return true;
+
+    return false;
----------------
luporl wrote:

```suggestion
    if (collectImplicit)
        return sym->test(Fortran::semantics::Symbol::Flag::OmpImplicit);
    if (collectPreDetermined)
        return sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined);
    return !sym->test(Fortran::semantics::Symbol::Flag::OmpImplicit) &&
        !sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined);
```

`collectImplicit` and `collectPreDetermined` will never be both true and when collecting implicit or pre-determined symbols you'll only want to collect those symbols marked with the corresponding flag.
Also, no symbol should have both `OmpPreDetermined` and `OmpImplicit` flags.

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


More information about the flang-commits mailing list