Skip to content

Commit a45bbd4

Browse files
authored
[flang][OpenMP] Dump requirement clauses/flags in WithOmpDeclarative (#163450)
1 parent 34fdd74 commit a45bbd4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class WithOmpDeclarative {
7373
ompAtomicDefaultMemOrder_ = flags;
7474
}
7575

76+
friend llvm::raw_ostream &operator<<(
77+
llvm::raw_ostream &, const WithOmpDeclarative &);
78+
7679
private:
7780
std::optional<RequiresClauses> ompRequires_;
7881
std::optional<common::OmpMemoryOrderType> ompAtomicDefaultMemOrder_;

flang/lib/Semantics/symbol.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ static void DumpList(llvm::raw_ostream &os, const char *label, const T &list) {
7070
}
7171
}
7272

73+
llvm::raw_ostream &operator<<(
74+
llvm::raw_ostream &os, const WithOmpDeclarative &x) {
75+
if (x.has_ompRequires() || x.has_ompAtomicDefaultMemOrder()) {
76+
os << " OmpRequirements:(";
77+
if (const common::OmpMemoryOrderType *admo{x.ompAtomicDefaultMemOrder()}) {
78+
os << parser::ToLowerCaseLetters(llvm::omp::getOpenMPClauseName(
79+
llvm::omp::Clause::OMPC_atomic_default_mem_order))
80+
<< '(' << parser::ToLowerCaseLetters(EnumToString(*admo)) << ')';
81+
if (x.has_ompRequires()) {
82+
os << ',';
83+
}
84+
}
85+
if (const WithOmpDeclarative::RequiresClauses *reqs{x.ompRequires()}) {
86+
size_t num{0}, size{reqs->count()};
87+
reqs->IterateOverMembers([&](llvm::omp::Clause f) {
88+
os << parser::ToLowerCaseLetters(llvm::omp::getOpenMPClauseName(f));
89+
if (++num < size) {
90+
os << ',';
91+
}
92+
});
93+
}
94+
os << ')';
95+
}
96+
return os;
97+
}
98+
7399
void SubprogramDetails::set_moduleInterface(Symbol &symbol) {
74100
CHECK(!moduleInterface_);
75101
moduleInterface_ = &symbol;
@@ -150,6 +176,7 @@ llvm::raw_ostream &operator<<(
150176
os << x;
151177
}
152178
}
179+
os << static_cast<const WithOmpDeclarative &>(x);
153180
return os;
154181
}
155182

@@ -580,7 +607,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Details &details) {
580607
common::visit( //
581608
common::visitors{
582609
[&](const UnknownDetails &) {},
583-
[&](const MainProgramDetails &) {},
610+
[&](const MainProgramDetails &x) {
611+
os << static_cast<const WithOmpDeclarative &>(x);
612+
},
584613
[&](const ModuleDetails &x) {
585614
if (x.isSubmodule()) {
586615
os << " (";
@@ -599,6 +628,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Details &details) {
599628
if (x.isDefaultPrivate()) {
600629
os << " isDefaultPrivate";
601630
}
631+
os << static_cast<const WithOmpDeclarative &>(x);
602632
},
603633
[&](const SubprogramNameDetails &x) {
604634
os << ' ' << EnumToString(x.kind());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!RUN: %flang_fc1 -fopenmp -fopenmp-version=60 -fdebug-dump-symbols %s | FileCheck %s
2+
3+
module fred
4+
!$omp requires atomic_default_mem_order(relaxed)
5+
contains
6+
subroutine f00
7+
!$omp requires unified_address
8+
end
9+
subroutine f01
10+
!$omp requires unified_shared_memory
11+
end
12+
end module
13+
14+
!CHECK: fred: Module OmpRequirements:(atomic_default_mem_order(relaxed),unified_address,unified_shared_memory)

0 commit comments

Comments
 (0)