[flang-commits] [flang] [flang][mlir] Add flang to mlir lowering for groupprivate (PR #180934)
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 10 02:53:01 PDT 2026
================
@@ -5431,13 +5551,42 @@ void Fortran::lower::genOpenMPSymbolProperties(
assert(var.hasSymbol() && "Expecting Symbol");
const semantics::Symbol &sym = var.getSymbol();
+ if (sym.test(semantics::Symbol::Flag::OmpGroupPrivate))
+ lower::genGroupprivateOp(converter, var);
+
if (sym.test(semantics::Symbol::Flag::OmpThreadprivate))
lower::genThreadprivateOp(converter, var);
if (sym.test(semantics::Symbol::Flag::OmpDeclareTarget))
lower::genDeclareTargetIntGlobal(converter, var);
}
+void Fortran::lower::genGroupprivateOp(lower::AbstractConverter &converter,
+ const lower::pft::Variable &var) {
+ const semantics::Symbol &sym = var.getSymbol();
+
+ // For common block members, the groupprivate op is generated for the entire
+ // common block in groupprivatizeVars, not for individual members here.
+ // The common block already has a global, so nothing to do here.
+ if (semantics::FindCommonBlockContaining(sym.GetUltimate()))
+ return;
+
+ // Handle non-global variables: local variables with the SAVE attribute can
+ // appear in a groupprivate directive. Promote them to fir.global so that
+ // omp.groupprivate can reference them by symbol name.
+ if (!var.isGlobal()) {
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ mlir::Location currentLocation = converter.getCurrentLocation();
+ auto module = converter.getModuleOp();
+ std::string globalName = converter.mangleName(sym);
+ if (!module.lookupSymbol<fir::GlobalOp>(globalName))
+ globalInitialization(converter, firOpBuilder, sym, var, currentLocation);
+ }
+
+ // The actual omp.groupprivate operation is created by groupprivatizeVars
+ // when entering a teams region.
----------------
skc7 wrote:
Done.
https://github.com/llvm/llvm-project/pull/180934
More information about the flang-commits
mailing list