Skip to content

Commit f4972a2

Browse files
authored
[flang][OpenMP] Use GetOmpDirectiveName to find directive source location (#150955)
1 parent 67c6604 commit f4972a2

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -389,42 +389,16 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
389389
}
390390
}
391391

392-
static const parser::CharBlock *
393-
getSource(const semantics::SemanticsContext &semaCtx,
394-
const lower::pft::Evaluation &eval) {
395-
const parser::CharBlock *source = nullptr;
396-
397-
auto ompConsVisit = [&](const parser::OpenMPConstruct &x) {
398-
std::visit(
399-
common::visitors{
400-
[&](const parser::OpenMPSectionsConstruct &x) {
401-
source = &std::get<0>(x.t).source;
402-
},
403-
[&](const parser::OpenMPLoopConstruct &x) {
404-
source = &std::get<0>(x.t).source;
405-
},
406-
[&](const parser::OpenMPBlockConstruct &x) {
407-
source = &std::get<0>(x.t).source;
408-
},
409-
[&](const parser::OpenMPCriticalConstruct &x) {
410-
source = &std::get<0>(x.t).source;
411-
},
412-
[&](const parser::OpenMPAtomicConstruct &x) {
413-
source = &std::get<parser::OmpDirectiveSpecification>(x.t).source;
414-
},
415-
[&](const auto &x) { source = &x.source; },
416-
},
417-
x.u);
418-
};
419-
420-
eval.visit(common::visitors{
421-
[&](const parser::OpenMPConstruct &x) { ompConsVisit(x); },
422-
[&](const parser::OpenMPDeclarativeConstruct &x) { source = &x.source; },
423-
[&](const parser::OmpEndLoopDirective &x) { source = &x.source; },
424-
[&](const auto &x) {},
392+
static parser::CharBlock getSource(const semantics::SemanticsContext &semaCtx,
393+
const lower::pft::Evaluation &eval) {
394+
return eval.visit(common::visitors{
395+
[&](const parser::OpenMPConstruct &x) {
396+
return parser::omp::GetOmpDirectiveName(x).source;
397+
},
398+
[&](const parser::OpenMPDeclarativeConstruct &x) { return x.source; },
399+
[&](const parser::OmpEndLoopDirective &x) { return x.source; },
400+
[&](const auto &x) { return parser::CharBlock{}; },
425401
});
426-
427-
return source;
428402
}
429403

430404
static void collectPrivatizingConstructs(
@@ -518,11 +492,11 @@ void DataSharingProcessor::collectSymbols(
518492
for (const semantics::Scope &child : scope->children())
519493
collectScopes(&child);
520494
};
521-
const parser::CharBlock *source =
522-
clauses.empty() ? getSource(semaCtx, eval) : &clauses.front().source;
495+
parser::CharBlock source =
496+
clauses.empty() ? getSource(semaCtx, eval) : clauses.front().source;
523497
const semantics::Scope *curScope = nullptr;
524-
if (source && !source->empty()) {
525-
curScope = &semaCtx.FindScope(*source);
498+
if (!source.empty()) {
499+
curScope = &semaCtx.FindScope(source);
526500
collectScopes(curScope);
527501
}
528502
// Collect all symbols referenced in the evaluation being processed,

0 commit comments

Comments
 (0)