[flang-commits] [flang] [flang][OpenMP] Privatize indirectly referenced symbols (PR #187097)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Mon Mar 23 02:52:10 PDT 2026


================
@@ -461,55 +462,47 @@ void DataSharingProcessor::collectSymbolsInNestedRegions(
   }
 }
 
-// Collect symbols to be default privatized in two steps.
-// In step 1, collect all symbols in `eval` that match `flag` into
-// `defaultSymbols`. In step 2, for nested constructs (if any), if and only if
-// the nested construct is an OpenMP construct, collect those nested
-// symbols skipping host associated symbols into `symbolsInNestedRegions`.
-// Later, in current context, all symbols in the set
-// `defaultSymbols` - `symbolsInNestedRegions` will be privatized.
-void DataSharingProcessor::collectSymbols(
-    semantics::Symbol::Flag flag,
-    llvm::SetVector<const semantics::Symbol *> &symbols) {
-  // Collect all scopes associated with 'eval'.
-  llvm::SetVector<const semantics::Scope *> clauseScopes;
-  std::function<void(const semantics::Scope *)> collectScopes =
+// Collect all scopes associated with `eval` and return the current scope.
+static const semantics::Scope *
+collectScopes(semantics::SemanticsContext &semaCtx,
+              lower::pft::Evaluation &eval,
+              llvm::SetVector<const semantics::Scope *> &clauseScopes) {
+  std::function<void(const semantics::Scope *)> collect =
       [&](const semantics::Scope *scope) {
         clauseScopes.insert(scope);
         for (const semantics::Scope &child : scope->children())
-          collectScopes(&child);
+          collect(&child);
       };
   parser::CharBlock source = getSource(semaCtx, eval);
   const semantics::Scope *curScope = nullptr;
   if (!source.empty()) {
     curScope = &semaCtx.FindScope(source);
-    collectScopes(curScope);
+    collect(curScope);
   }
-  // Collect all symbols referenced in the evaluation being processed,
-  // that matches 'flag'.
-  llvm::SetVector<const semantics::Symbol *> allSymbols;
-  converter.collectSymbolSet(eval, allSymbols, flag,
-                             /*collectSymbols=*/true,
-                             /*collectHostAssociatedSymbols=*/true);
-
-  llvm::SetVector<const semantics::Symbol *> symbolsInNestedRegions;
-  collectSymbolsInNestedRegions(eval, flag, symbolsInNestedRegions);
+  return curScope;
+}
 
-  for (auto *symbol : allSymbols)
-    if (visitor.isSymbolDefineBy(symbol, eval))
-      symbolsInNestedRegions.remove(symbol);
+static bool isPrivatizable(const semantics::Symbol &sym) {
----------------
kiranchandramohan wrote:

Thanks. Feel free to go ahead.

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


More information about the flang-commits mailing list