Skip to content

Commit af66368

Browse files
[clang] [OpenMP] New OpenMP 6.0 - Parsing and Sema support for groupprivate (#158134)
1 parent 1dc6bf3 commit af66368

File tree

26 files changed

+476
-16
lines changed

26 files changed

+476
-16
lines changed

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ implementation.
578578
| | | | |
579579
| | | | Flang parser: https://github.com/llvm/llvm-project/pull/153807 |
580580
| | | | Flang sema: https://github.com/llvm/llvm-project/pull/154779 |
581+
| | | | Clang parse/sema: https://github.com/llvm/llvm-project/pull/158134 |
581582
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
582583
| variable-category on default clause | :good:`done` | :none:`unclaimed` | |
583584
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ OpenMP Support
566566
- Added support for ``variable-category`` modifier in ``default clause``.
567567
- Added support for ``defaultmap`` directive implicit-behavior ``storage``.
568568
- Added support for ``defaultmap`` directive implicit-behavior ``private``.
569+
- Added parsing and semantic analysis support for ``groupprivate`` directive.
569570

570571
Improvements
571572
^^^^^^^^^^^^

clang/include/clang/AST/ASTMutationListener.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class ASTMutationListener {
125125
/// \param D the declaration marked OpenMP threadprivate.
126126
virtual void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {}
127127

128+
/// A declaration is marked as OpenMP groupprivate which was not
129+
/// previously marked as groupprivate.
130+
///
131+
/// \param D the declaration marked OpenMP groupprivate.
132+
virtual void DeclarationMarkedOpenMPGroupPrivate(const Decl *D) {}
133+
128134
/// A declaration is marked as OpenMP declaretarget which was not
129135
/// previously marked as declaretarget.
130136
///

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ class ASTNodeTraverser
620620
Visit(E);
621621
}
622622

623+
void VisitOMPGroupPrivateDecl(const OMPGroupPrivateDecl *D) {
624+
for (const auto *E : D->varlist())
625+
Visit(E);
626+
}
627+
623628
void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
624629
Visit(D->getCombiner());
625630
if (const auto *Initializer = D->getInitializer())

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,68 @@ class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> {
158158
static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
159159
};
160160

161+
/// This represents '#pragma omp groupprivate ...' directive.
162+
/// For example, in the following, both 'a' and 'A::b' are groupprivate:
163+
///
164+
/// \code
165+
/// int a;
166+
/// #pragma omp groupprivate(a)
167+
/// struct A {
168+
/// static int b;
169+
/// #pragma omp groupprivate(b)
170+
/// };
171+
/// \endcode
172+
///
173+
class OMPGroupPrivateDecl final : public OMPDeclarativeDirective<Decl> {
174+
friend class OMPDeclarativeDirective<Decl>;
175+
176+
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
177+
178+
OMPGroupPrivateDecl(DeclContext *DC = nullptr,
179+
SourceLocation L = SourceLocation())
180+
: OMPDeclarativeDirective<Decl>(OMPGroupPrivate, DC, L) {}
181+
182+
ArrayRef<const Expr *> getVars() const {
183+
auto **Storage = reinterpret_cast<Expr **>(Data->getChildren().data());
184+
return {Storage, Data->getNumChildren()};
185+
}
186+
187+
MutableArrayRef<Expr *> getVars() {
188+
auto **Storage = reinterpret_cast<Expr **>(Data->getChildren().data());
189+
return {Storage, Data->getNumChildren()};
190+
}
191+
192+
void setVars(ArrayRef<Expr *> VL);
193+
194+
public:
195+
static OMPGroupPrivateDecl *Create(ASTContext &C, DeclContext *DC,
196+
SourceLocation L, ArrayRef<Expr *> VL);
197+
static OMPGroupPrivateDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
198+
unsigned N);
199+
200+
typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
201+
typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
202+
typedef llvm::iterator_range<varlist_iterator> varlist_range;
203+
typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
204+
205+
unsigned varlist_size() const { return Data->getNumChildren(); }
206+
bool varlist_empty() const { return Data->getChildren().empty(); }
207+
208+
varlist_range varlist() {
209+
return varlist_range(varlist_begin(), varlist_end());
210+
}
211+
varlist_const_range varlist() const {
212+
return varlist_const_range(varlist_begin(), varlist_end());
213+
}
214+
varlist_iterator varlist_begin() { return getVars().begin(); }
215+
varlist_iterator varlist_end() { return getVars().end(); }
216+
varlist_const_iterator varlist_begin() const { return getVars().begin(); }
217+
varlist_const_iterator varlist_end() const { return getVars().end(); }
218+
219+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
220+
static bool classofKind(Kind K) { return K == OMPGroupPrivate; }
221+
};
222+
161223
enum class OMPDeclareReductionInitKind {
162224
Call, // Initialized by function call.
163225
Direct, // omp_priv(<expr>)

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,12 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
18871887
}
18881888
})
18891889

1890+
DEF_TRAVERSE_DECL(OMPGroupPrivateDecl, {
1891+
for (auto *I : D->varlist()) {
1892+
TRY_TO(TraverseStmt(I));
1893+
}
1894+
})
1895+
18901896
DEF_TRAVERSE_DECL(OMPRequiresDecl, {
18911897
for (auto *C : D->clauselists()) {
18921898
TRY_TO(TraverseOMPClause(C));

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,12 @@ def OMPThreadPrivateDecl : InheritableAttr {
45854585
let Documentation = [InternalOnly];
45864586
}
45874587

4588+
def OMPGroupPrivateDecl : InheritableAttr {
4589+
let Spellings = [];
4590+
let SemaHandler = 0;
4591+
let Documentation = [InternalOnly];
4592+
}
4593+
45884594
def OMPCaptureNoInit : InheritableAttr {
45894595
// This attribute has no spellings as it is only ever created implicitly.
45904596
let Spellings = [];

clang/include/clang/Basic/DeclNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def OutlinedFunction : DeclNode<Decl>, DeclContext;
106106
def Captured : DeclNode<Decl>, DeclContext;
107107
def Import : DeclNode<Decl>;
108108
def OMPThreadPrivate : DeclNode<Decl>;
109+
def OMPGroupPrivate : DeclNode<Decl>;
109110
def OMPAllocate : DeclNode<Decl>;
110111
def OMPRequires : DeclNode<Decl>;
111112
def Empty : DeclNode<Decl>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11708,6 +11708,10 @@ def err_omp_threadprivate_incomplete_type : Error<
1170811708
"threadprivate variable with incomplete type %0">;
1170911709
def err_omp_no_dsa_for_variable : Error<
1171011710
"variable %0 must have explicitly specified data sharing attributes">;
11711+
def err_omp_groupprivate_incomplete_type : Error<
11712+
"groupprivate variable with incomplete type %0">;
11713+
def err_omp_groupprivate_with_initializer : Error<
11714+
"variable %0 with initializer cannot appear in groupprivate directive">;
1171111715
def err_omp_defaultmap_no_attr_for_variable : Error<
1171211716
"variable %0 must have explicitly specified data sharing attributes, data mapping attributes, or in an is_device_ptr clause">;
1171311717
def note_omp_default_dsa_none : Note<

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ class SemaOpenMP : public SemaBase {
227227
/// Builds a new OpenMPThreadPrivateDecl and checks its correctness.
228228
OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc,
229229
ArrayRef<Expr *> VarList);
230+
/// Called on well-formed '#pragma omp groupprivate'.
231+
DeclGroupPtrTy ActOnOpenMPGroupPrivateDirective(SourceLocation Loc,
232+
ArrayRef<Expr *> VarList);
233+
/// Builds a new OpenMPGroupPrivateDecl and checks its correctness.
234+
OMPGroupPrivateDecl *CheckOMPGroupPrivateDecl(SourceLocation Loc,
235+
ArrayRef<Expr *> VarList);
230236
/// Called on well-formed '#pragma omp allocate'.
231237
DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc,
232238
ArrayRef<Expr *> VarList,

0 commit comments

Comments
 (0)