@@ -29,10 +29,9 @@ void DataSharingProcessor::processStep1(
2929 collectSymbolsForPrivatization ();
3030 collectDefaultSymbols ();
3131 collectImplicitSymbols ();
32- collectPreDeterminedSymbols ();
33-
3432 privatize (clauseOps, privateSyms);
35-
33+ defaultPrivatize (clauseOps, privateSyms);
34+ implicitPrivatize (clauseOps, privateSyms);
3635 insertBarrier ();
3736}
3837
@@ -58,7 +57,7 @@ void DataSharingProcessor::processStep2(mlir::Operation *op, bool isLoop) {
5857}
5958
6059void DataSharingProcessor::insertDeallocs () {
61- for (const semantics::Symbol *sym : allPrivatizedSymbols )
60+ for (const semantics::Symbol *sym : privatizedSymbols )
6261 if (semantics::IsAllocatable (sym->GetUltimate ())) {
6362 if (!useDelayedPrivatization) {
6463 converter.createHostAssociateVarCloneDealloc (*sym);
@@ -93,6 +92,10 @@ void DataSharingProcessor::insertDeallocs() {
9392}
9493
9594void DataSharingProcessor::cloneSymbol (const semantics::Symbol *sym) {
95+ // Privatization for symbols which are pre-determined (like loop index
96+ // variables) happen separately, for everything else privatize here.
97+ if (sym->test (semantics::Symbol::Flag::OmpPreDetermined))
98+ return ;
9699 bool success = converter.createHostAssociateVarClone (*sym);
97100 (void )success;
98101 assert (success && " Privatization failed due to existing binding" );
@@ -123,24 +126,20 @@ void DataSharingProcessor::collectSymbolsForPrivatization() {
123126 for (const omp::Clause &clause : clauses) {
124127 if (const auto &privateClause =
125128 std::get_if<omp::clause::Private>(&clause.u )) {
126- collectOmpObjectListSymbol (privateClause->v , explicitlyPrivatizedSymbols );
129+ collectOmpObjectListSymbol (privateClause->v , privatizedSymbols );
127130 } else if (const auto &firstPrivateClause =
128131 std::get_if<omp::clause::Firstprivate>(&clause.u )) {
129- collectOmpObjectListSymbol (firstPrivateClause->v ,
130- explicitlyPrivatizedSymbols);
132+ collectOmpObjectListSymbol (firstPrivateClause->v , privatizedSymbols);
131133 } else if (const auto &lastPrivateClause =
132134 std::get_if<omp::clause::Lastprivate>(&clause.u )) {
133135 const ObjectList &objects = std::get<ObjectList>(lastPrivateClause->t );
134- collectOmpObjectListSymbol (objects, explicitlyPrivatizedSymbols );
136+ collectOmpObjectListSymbol (objects, privatizedSymbols );
135137 hasLastPrivateOp = true ;
136138 } else if (std::get_if<omp::clause::Collapse>(&clause.u )) {
137139 hasCollapse = true ;
138140 }
139141 }
140142
141- for (auto *sym : explicitlyPrivatizedSymbols)
142- allPrivatizedSymbols.insert (sym);
143-
144143 if (hasCollapse && hasLastPrivateOp)
145144 TODO (converter.getCurrentLocation (), " Collapse clause with lastprivate" );
146145}
@@ -150,7 +149,7 @@ bool DataSharingProcessor::needBarrier() {
150149 // initialization of firstprivate variables and post-update of lastprivate
151150 // variables.
152151 // Emit implicit barrier for linear clause. Maybe on somewhere else.
153- for (const semantics::Symbol *sym : allPrivatizedSymbols ) {
152+ for (const semantics::Symbol *sym : privatizedSymbols ) {
154153 if (sym->test (semantics::Symbol::Flag::OmpFirstPrivate) &&
155154 sym->test (semantics::Symbol::Flag::OmpLastPrivate))
156155 return true ;
@@ -284,40 +283,10 @@ void DataSharingProcessor::collectSymbolsInNestedRegions(
284283 if (nestedEval.isConstruct ())
285284 // Recursively look for OpenMP constructs within `nestedEval`'s region
286285 collectSymbolsInNestedRegions (nestedEval, flag, symbolsInNestedRegions);
287- else {
288- bool isOrderedConstruct = [&]() {
289- if (auto *ompConstruct =
290- nestedEval.getIf <parser::OpenMPConstruct>()) {
291- if (auto *ompBlockConstruct =
292- std::get_if<parser::OpenMPBlockConstruct>(
293- &ompConstruct->u )) {
294- const auto &beginBlockDirective =
295- std::get<parser::OmpBeginBlockDirective>(
296- ompBlockConstruct->t );
297- const auto origDirective =
298- std::get<parser::OmpBlockDirective>(beginBlockDirective.t ).v ;
299-
300- return origDirective == llvm::omp::Directive::OMPD_ordered;
301- }
302- }
303-
304- return false ;
305- }();
306-
307- bool isCriticalConstruct = [&]() {
308- if (auto *ompConstruct =
309- nestedEval.getIf <parser::OpenMPConstruct>()) {
310- return std::get_if<parser::OpenMPCriticalConstruct>(
311- &ompConstruct->u ) != nullptr ;
312- }
313- return false ;
314- }();
315-
316- if (!isOrderedConstruct && !isCriticalConstruct)
317- converter.collectSymbolSet (nestedEval, symbolsInNestedRegions, flag,
318- /* collectSymbols=*/ true ,
319- /* collectHostAssociatedSymbols=*/ false );
320- }
286+ else
287+ converter.collectSymbolSet (nestedEval, symbolsInNestedRegions, flag,
288+ /* collectSymbols=*/ true ,
289+ /* collectHostAssociatedSymbols=*/ false );
321290 }
322291 }
323292}
@@ -353,39 +322,24 @@ void DataSharingProcessor::collectSymbols(
353322 converter.collectSymbolSet (eval, allSymbols, flag,
354323 /* collectSymbols=*/ true ,
355324 /* collectHostAssociatedSymbols=*/ true );
356-
357325 llvm::SetVector<const semantics::Symbol *> symbolsInNestedRegions;
358326 collectSymbolsInNestedRegions (eval, flag, symbolsInNestedRegions);
359327 // Filter-out symbols that must not be privatized.
360328 bool collectImplicit = flag == semantics::Symbol::Flag::OmpImplicit;
361- bool collectPreDetermined = flag == semantics::Symbol::Flag::OmpPreDetermined;
362-
363329 auto isPrivatizable = [](const semantics::Symbol &sym) -> bool {
364330 return !semantics::IsProcedure (sym) &&
365331 !sym.GetUltimate ().has <semantics::DerivedTypeDetails>() &&
366332 !sym.GetUltimate ().has <semantics::NamelistDetails>() &&
367333 !semantics::IsImpliedDoIndex (sym.GetUltimate ());
368334 };
369-
370- auto shouldCollectSymbol = [&](const semantics::Symbol *sym) {
371- if (collectImplicit)
372- return sym->test (semantics::Symbol::Flag::OmpImplicit);
373-
374- if (collectPreDetermined)
375- return sym->test (semantics::Symbol::Flag::OmpPreDetermined);
376-
377- return !sym->test (semantics::Symbol::Flag::OmpImplicit) &&
378- !sym->test (semantics::Symbol::Flag::OmpPreDetermined);
379- };
380-
381335 for (const auto *sym : allSymbols) {
382336 assert (curScope && " couldn't find current scope" );
383337 if (isPrivatizable (*sym) && !symbolsInNestedRegions.contains (sym) &&
384- !explicitlyPrivatizedSymbols.contains (sym) &&
385- shouldCollectSymbol (sym) && clauseScopes.contains (&sym->owner ())) {
386- allPrivatizedSymbols.insert (sym);
338+ !privatizedSymbols.contains (sym) &&
339+ !sym->test (semantics::Symbol::Flag::OmpPreDetermined) &&
340+ (collectImplicit || !sym->test (semantics::Symbol::Flag::OmpImplicit)) &&
341+ clauseScopes.contains (&sym->owner ()))
387342 symbols.insert (sym);
388- }
389343 }
390344}
391345
@@ -409,16 +363,10 @@ void DataSharingProcessor::collectImplicitSymbols() {
409363 collectSymbols (semantics::Symbol::Flag::OmpImplicit, implicitSymbols);
410364}
411365
412- void DataSharingProcessor::collectPreDeterminedSymbols () {
413- if (shouldCollectPreDeterminedSymbols)
414- collectSymbols (semantics::Symbol::Flag::OmpPreDetermined,
415- preDeterminedSymbols);
416- }
417-
418366void DataSharingProcessor::privatize (
419367 mlir::omp::PrivateClauseOps *clauseOps,
420368 llvm::SmallVectorImpl<const semantics::Symbol *> *privateSyms) {
421- for (const semantics::Symbol *sym : allPrivatizedSymbols ) {
369+ for (const semantics::Symbol *sym : privatizedSymbols ) {
422370 if (const auto *commonDet =
423371 sym->detailsIf <semantics::CommonBlockDetails>()) {
424372 for (const auto &mem : commonDet->objects ())
@@ -430,7 +378,7 @@ void DataSharingProcessor::privatize(
430378
431379void DataSharingProcessor::copyLastPrivatize (mlir::Operation *op) {
432380 insertLastPrivateCompare (op);
433- for (const semantics::Symbol *sym : allPrivatizedSymbols )
381+ for (const semantics::Symbol *sym : privatizedSymbols )
434382 if (const auto *commonDet =
435383 sym->detailsIf <semantics::CommonBlockDetails>()) {
436384 for (const auto &mem : commonDet->objects ()) {
@@ -441,6 +389,20 @@ void DataSharingProcessor::copyLastPrivatize(mlir::Operation *op) {
441389 }
442390}
443391
392+ void DataSharingProcessor::defaultPrivatize (
393+ mlir::omp::PrivateClauseOps *clauseOps,
394+ llvm::SmallVectorImpl<const semantics::Symbol *> *privateSyms) {
395+ for (const semantics::Symbol *sym : defaultSymbols)
396+ doPrivatize (sym, clauseOps, privateSyms);
397+ }
398+
399+ void DataSharingProcessor::implicitPrivatize (
400+ mlir::omp::PrivateClauseOps *clauseOps,
401+ llvm::SmallVectorImpl<const semantics::Symbol *> *privateSyms) {
402+ for (const semantics::Symbol *sym : implicitSymbols)
403+ doPrivatize (sym, clauseOps, privateSyms);
404+ }
405+
444406void DataSharingProcessor::doPrivatize (
445407 const semantics::Symbol *sym, mlir::omp::PrivateClauseOps *clauseOps,
446408 llvm::SmallVectorImpl<const semantics::Symbol *> *privateSyms) {
0 commit comments