[OPENMP50]Support 'destroy' clause on 'depobj' directives.

Added basic support (parsing/sema/serialization) for 'destroy' clause in
depobj directives.
This commit is contained in:
Alexey Bataev 2020-03-02 14:21:20 -05:00
parent 6377676651
commit 375437ab92
16 changed files with 104 additions and 2 deletions

View File

@ -6693,6 +6693,46 @@ public:
}
};
/// This represents 'destroy' clause in the '#pragma omp depobj'
/// directive.
///
/// \code
/// #pragma omp depobj(a) destroy
/// \endcode
/// In this example directive '#pragma omp depobj' has 'destroy' clause.
class OMPDestroyClause final : public OMPClause {
public:
/// Build 'destroy' clause.
///
/// \param StartLoc Starting location of the clause.
/// \param EndLoc Ending location of the clause.
OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
: OMPClause(OMPC_destroy, StartLoc, EndLoc) {}
/// Build an empty clause.
OMPDestroyClause()
: OMPClause(OMPC_destroy, SourceLocation(), SourceLocation()) {}
child_range children() {
return child_range(child_iterator(), child_iterator());
}
const_child_range children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}
child_range used_children() {
return child_range(child_iterator(), child_iterator());
}
const_child_range used_children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}
static bool classof(const OMPClause *T) {
return T->getClauseKind() == OMPC_destroy;
}
};
/// This class implements a simple visitor for OMPClause
/// subclasses.
template<class ImplClass, template <typename> class Ptr, typename RetTy>

View File

@ -3159,6 +3159,11 @@ bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
return true;
}
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *) {
return true;
}
template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {

View File

@ -276,6 +276,7 @@ OPENMP_CLAUSE(allocate, OMPAllocateClause)
OPENMP_CLAUSE(nontemporal, OMPNontemporalClause)
OPENMP_CLAUSE(order, OMPOrderClause)
OPENMP_CLAUSE(depobj, OMPDepobjClause)
OPENMP_CLAUSE(destroy, OMPDestroyClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
@ -1084,6 +1085,7 @@ OPENMP_FLUSH_CLAUSE(release)
// Clauses allowed for OpenMP directive 'depobj'.
OPENMP_DEPOBJ_CLAUSE(depend)
OPENMP_DEPOBJ_CLAUSE(destroy)
#undef OPENMP_DEPOBJ_CLAUSE
#undef OPENMP_FLUSH_CLAUSE

View File

@ -10344,6 +10344,9 @@ public:
/// Called on well-formed 'relaxed' clause.
OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc,
SourceLocation EndLoc);
/// Called on well-formed 'destroy' clause.
OMPClause *ActOnOpenMPDestroyClause(SourceLocation StartLoc,
SourceLocation EndLoc);
/// Called on well-formed 'threads' clause.
OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc,
SourceLocation EndLoc);

View File

@ -143,6 +143,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
break;
}
@ -228,6 +229,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
break;
}
@ -1423,6 +1425,10 @@ void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
OS << ")";
}
void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) {
OS << "destroy";
}
template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(),

View File

@ -532,6 +532,8 @@ void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *) {}
template<typename T>
void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
for (auto *E : Node->varlists()) {

View File

@ -202,6 +202,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
case OMPC_dynamic_allocators:
case OMPC_match:
case OMPC_nontemporal:
case OMPC_destroy:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
@ -417,6 +418,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_dynamic_allocators:
case OMPC_match:
case OMPC_nontemporal:
case OMPC_destroy:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");

View File

@ -4581,6 +4581,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
}
}

View File

@ -2340,7 +2340,7 @@ bool Parser::ParseOpenMPSimpleVarList(
/// from-clause | is_device_ptr-clause | task_reduction-clause |
/// in_reduction-clause | allocator-clause | allocate-clause |
/// acq_rel-clause | acquire-clause | release-clause | relaxed-clause |
/// depobj-clause
/// depobj-clause | destroy-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
@ -2461,6 +2461,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
case OMPC_unified_shared_memory:
case OMPC_reverse_offload:
case OMPC_dynamic_allocators:
case OMPC_destroy:
// OpenMP [2.7.1, Restrictions, p. 9]
// Only one ordered clause can appear on a loop directive.
// OpenMP [2.7.1, Restrictions, C/C++, p. 4]

View File

@ -5041,6 +5041,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
case OMPC_is_device_ptr:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
continue;
case OMPC_allocator:
case OMPC_flush:
@ -10980,6 +10981,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
llvm_unreachable("Clause is not allowed.");
}
return Res;
@ -11705,6 +11707,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
llvm_unreachable("Unexpected OpenMP clause.");
}
return CaptureRegion;
@ -12137,6 +12140,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
case OMPC_device_type:
case OMPC_match:
case OMPC_nontemporal:
case OMPC_destroy:
llvm_unreachable("Clause is not allowed.");
}
return Res;
@ -12334,6 +12338,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
case OMPC_match:
case OMPC_nontemporal:
case OMPC_order:
case OMPC_destroy:
llvm_unreachable("Clause is not allowed.");
}
return Res;
@ -12513,6 +12518,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
case OMPC_dynamic_allocators:
Res = ActOnOpenMPDynamicAllocatorsClause(StartLoc, EndLoc);
break;
case OMPC_destroy:
Res = ActOnOpenMPDestroyClause(StartLoc, EndLoc);
break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
@ -12661,6 +12669,11 @@ OMPClause *Sema::ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc,
return new (Context) OMPDynamicAllocatorsClause(StartLoc, EndLoc);
}
OMPClause *Sema::ActOnOpenMPDestroyClause(SourceLocation StartLoc,
SourceLocation EndLoc) {
return new (Context) OMPDestroyClause(StartLoc, EndLoc);
}
OMPClause *Sema::ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
const OMPVarListLocTy &Locs, SourceLocation ColonLoc,
@ -12809,6 +12822,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
case OMPC_device_type:
case OMPC_match:
case OMPC_order:
case OMPC_destroy:
llvm_unreachable("Clause is not allowed.");
}
return Res;

View File

@ -8873,6 +8873,13 @@ TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
return C;
}
template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
// No need to rebuild this clause, no template-dependent parameters.
return C;
}
template <typename Derived>
OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
OMPUnifiedAddressClause *C) {

View File

@ -11827,6 +11827,9 @@ OMPClause *OMPClauseReader::readClause() {
case OMPC_order:
C = new (Context) OMPOrderClause();
break;
case OMPC_destroy:
C = new (Context) OMPDestroyClause();
break;
}
assert(C && "Unknown OMPClause type");
@ -11955,6 +11958,8 @@ void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {}
void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {}
void OMPClauseReader::VisitOMPDestroyClause(OMPDestroyClause *) {}
void OMPClauseReader::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {}
void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause(

View File

@ -6161,6 +6161,8 @@ void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {}
void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {}
void OMPClauseWriter::VisitOMPDestroyClause(OMPDestroyClause *) {}
void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
Record.push_back(C->varlist_size());
Record.AddSourceLocation(C->getLParenLoc());

View File

@ -18,12 +18,15 @@ template <class T>
T tmain(T argc) {
static T a;
#pragma omp depobj(a) depend(in:argc)
#pragma omp depobj(argc) destroy
return argc;
}
// CHECK: static T a;
// CHECK-NEXT: #pragma omp depobj (a) depend(in : argc){{$}}
// CHECK-NEXT: #pragma omp depobj (argc) destroy{{$}}
// CHECK: static void *a;
// CHECK-NEXT: #pragma omp depobj (a) depend(in : argc){{$}}
// CHECK-NEXT: #pragma omp depobj (argc) destroy{{$}}
int main(int argc, char **argv) {
static omp_depend_t a;
@ -31,7 +34,9 @@ int main(int argc, char **argv) {
// CHECK: static omp_depend_t a;
// CHECK-NEXT: omp_depend_t b;
#pragma omp depobj(a) depend(out:argc, argv)
#pragma omp depobj(b) destroy
// CHECK-NEXT: #pragma omp depobj (a) depend(out : argc,argv)
// CHECK-NEXT: #pragma omp depobj (b) destroy
(void)tmain(a), tmain(b);
return 0;
}

View File

@ -21,7 +21,7 @@ T tmain(T argc) {
#pragma omp depobj(x) untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp depobj'}}
#pragma omp depobj(x) unknown // expected-warning {{extra tokens at the end of '#pragma omp depobj' are ignored}}
if (argc)
#pragma omp depobj(x) depend(in:s) // expected-error {{'#pragma omp depobj' cannot be an immediate substatement}}
#pragma omp depobj(x) destroy // expected-error {{'#pragma omp depobj' cannot be an immediate substatement}}
if (argc) {
#pragma omp depobj(x) depend(in:s)
}
@ -143,9 +143,14 @@ label1 : {
;
#pragma omp depobj(x) seq_cst // expected-error {{unexpected OpenMP clause 'seq_cst' in directive '#pragma omp depobj'}}
#pragma omp depobj(x) depend(in: x)
#pragma omp depobj(x) destroy destroy // expected-error {{directive '#pragma omp depobj' cannot contain more than one 'destroy' clause}}
#pragma omp depobj(x) depend(in: x) destroy // expected-error {{exactly one of 'depend', 'destroy', or 'update' clauses is expected}}
#pragma omp depobj(x) destroy depend(in: x) // expected-error {{exactly one of 'depend', 'destroy', or 'update' clauses is expected}}
#pragma omp depobj(x) (x) depend(in: x) // expected-warning {{extra tokens at the end of '#pragma omp depobj' are ignored}}
#pragma omp depobj(x) depend(in: x) depend(out:x) // expected-error {{exactly one of 'depend', 'destroy', or 'update' clauses is expected}}
#pragma omp depend(out:x) depobj(x) // expected-error {{expected an OpenMP directive}}
#pragma omp destroy depobj(x) // expected-error {{expected an OpenMP directive}}
#pragma omp depobj depend(in:x) (x) // expected-error {{expected depobj expression}} expected-warning {{extra tokens at the end of '#pragma omp depobj' are ignored}}
#pragma omp depobj destroy (x) // expected-error {{expected depobj expression}} expected-warning {{extra tokens at the end of '#pragma omp depobj' are ignored}}
return tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}}
}

View File

@ -2250,6 +2250,8 @@ void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {}
void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {}
void OMPClauseEnqueue::VisitOMPDestroyClause(const OMPDestroyClause *) {}
void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
const OMPUnifiedAddressClause *) {}