summaryrefslogtreecommitdiffstats
path: root/flang/lib/Lower/OpenMP/OpenMP.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Lower/OpenMP/OpenMP.cpp')
-rw-r--r--flang/lib/Lower/OpenMP/OpenMP.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 5cff95c7d125..4f0bb80cd7fd 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -170,9 +170,10 @@ static void threadPrivatizeVars(Fortran::lower::AbstractConverter &converter,
};
llvm::SetVector<const Fortran::semantics::Symbol *> threadprivateSyms;
- converter.collectSymbolSet(
- eval, threadprivateSyms,
- Fortran::semantics::Symbol::Flag::OmpThreadprivate);
+ converter.collectSymbolSet(eval, threadprivateSyms,
+ Fortran::semantics::Symbol::Flag::OmpThreadprivate,
+ /*collectSymbols=*/true,
+ /*collectHostAssociatedSymbols=*/true);
std::set<Fortran::semantics::SourceName> threadprivateSymNames;
// For a COMMON block, the ThreadprivateOp is generated for itself instead of
@@ -2276,8 +2277,15 @@ void Fortran::lower::genThreadprivateOp(
// variable in main program, and it has implicit SAVE attribute. Take it as
// with SAVE attribute, so to create GlobalOp for it to simplify the
// translation to LLVM IR.
- fir::GlobalOp global = globalInitialization(converter, firOpBuilder, sym,
- var, currentLocation);
+ // Avoids performing multiple globalInitializations.
+ fir::GlobalOp global;
+ auto module = converter.getModuleOp();
+ std::string globalName = converter.mangleName(sym);
+ if (module.lookupSymbol<fir::GlobalOp>(globalName))
+ global = module.lookupSymbol<fir::GlobalOp>(globalName);
+ else
+ global = globalInitialization(converter, firOpBuilder, sym, var,
+ currentLocation);
mlir::Value symValue = firOpBuilder.create<fir::AddrOfOp>(
currentLocation, global.resultType(), global.getSymbol());