Skip to content

Commit

Permalink
[Flang][OpenMP][Parser] Resolve Declare Target Directive Symbols
Browse files Browse the repository at this point in the history
Currently symbols are not resolved for declare target
after they've been modified by prior passes. This can
lead to missing or incorrect symbols in subsequent
compiler phases when declare target is used with
more complex types e.g. common block.

This patch should allow these symbols to be
resolved appropriately.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151993
  • Loading branch information
agozillon committed Jun 2, 2023
1 parent cfde5f2 commit 70fc081
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
24 changes: 23 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
}
void Post(const parser::OpenMPRequiresConstruct &) { PopContext(); }

bool Pre(const parser::OpenMPDeclareTargetConstruct &);
void Post(const parser::OpenMPDeclareTargetConstruct &) { PopContext(); }

bool Pre(const parser::OpenMPThreadprivate &);
void Post(const parser::OpenMPThreadprivate &) { PopContext(); }

Expand Down Expand Up @@ -520,7 +523,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
Symbol::Flag::OmpUseDeviceAddr};

static constexpr Symbol::Flags ompFlagsRequireMark{
Symbol::Flag::OmpThreadprivate};
Symbol::Flag::OmpThreadprivate, Symbol::Flag::OmpDeclareTarget};

static constexpr Symbol::Flags dataCopyingAttributeFlags{
Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpCopyPrivate};
Expand Down Expand Up @@ -1468,6 +1471,25 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
return true;
}

bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclareTargetConstruct &x) {
PushContext(x.source, llvm::omp::Directive::OMPD_declare_target);
const auto &spec{std::get<parser::OmpDeclareTargetSpecifier>(x.t)};
if (const auto *objectList{parser::Unwrap<parser::OmpObjectList>(spec.u)}) {
ResolveOmpObjectList(*objectList, Symbol::Flag::OmpDeclareTarget);
} else if (const auto *clauseList{
parser::Unwrap<parser::OmpClauseList>(spec.u)}) {
for (const auto &clause : clauseList->v) {
if (const auto *toClause{std::get_if<parser::OmpClause::To>(&clause.u)}) {
ResolveOmpObjectList(toClause->v, Symbol::Flag::OmpDeclareTarget);
} else if (const auto *linkClause{
std::get_if<parser::OmpClause::Link>(&clause.u)}) {
ResolveOmpObjectList(linkClause->v, Symbol::Flag::OmpDeclareTarget);
}
}
}
return true;
}

bool OmpAttributeVisitor::Pre(const parser::OpenMPThreadprivate &x) {
PushContext(x.source, llvm::omp::Directive::OMPD_threadprivate);
const auto &list{std::get<parser::OmpObjectList>(x.t)};
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Semantics/OpenMP/declare-target-common-block.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s

PROGRAM main
!CHECK: one (OmpDeclareTarget) size=4 offset=0: ObjectEntity type: REAL(4)
!CHECK: two (OmpDeclareTarget) size=4 offset=4: ObjectEntity type: REAL(4)
!CHECK: numbers size=8 offset=0: CommonBlockDetails alignment=4: one two
REAL :: one, two
COMMON /numbers/ one, two
!$omp declare target(/numbers/)
END

0 comments on commit 70fc081

Please sign in to comment.