[flang-commits] [flang] 70fc081 - [Flang][OpenMP][Parser] Resolve Declare Target Directive Symbols
Andrew Gozillon via flang-commits
flang-commits at lists.llvm.org
Fri Jun 2 12:29:13 PDT 2023
Author: Andrew Gozillon
Date: 2023-06-02T14:28:48-05:00
New Revision: 70fc081f74520fc0809060ecba011773105456d5
URL: https://github.com/llvm/llvm-project/commit/70fc081f74520fc0809060ecba011773105456d5
DIFF: https://github.com/llvm/llvm-project/commit/70fc081f74520fc0809060ecba011773105456d5.diff
LOG: [Flang][OpenMP][Parser] Resolve Declare Target Directive Symbols
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
Added:
flang/test/Semantics/OpenMP/declare-target-common-block.f90
Modified:
flang/lib/Semantics/resolve-directives.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 8c3067d1b0a36..73f451a9bd536 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -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(); }
@@ -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};
@@ -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)};
diff --git a/flang/test/Semantics/OpenMP/declare-target-common-block.f90 b/flang/test/Semantics/OpenMP/declare-target-common-block.f90
new file mode 100644
index 0000000000000..33a093a03a227
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-target-common-block.f90
@@ -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
More information about the flang-commits
mailing list