Skip to content

Commit 1e054e6

Browse files
committed
[OPENMP5.1] Initial support for severity clause
Differential Revision:https://reviews.llvm.org/D138227
1 parent 622d329 commit 1e054e6

File tree

19 files changed

+266
-25
lines changed

19 files changed

+266
-25
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,86 @@ class OMPAtClause final : public OMPClause {
16421642
}
16431643
};
16441644

1645+
/// This represents 'severity' clause in the '#pragma omp error' directive
1646+
///
1647+
/// \code
1648+
/// #pragma omp error severity(fatal)
1649+
/// \endcode
1650+
/// In this example directive '#pragma omp error' has simple
1651+
/// 'severity' clause with kind 'fatal'.
1652+
class OMPSeverityClause final : public OMPClause {
1653+
friend class OMPClauseReader;
1654+
1655+
/// Location of '('
1656+
SourceLocation LParenLoc;
1657+
1658+
/// A kind of the 'severity' clause.
1659+
OpenMPSeverityClauseKind Kind = OMPC_SEVERITY_unknown;
1660+
1661+
/// Start location of the kind in source code.
1662+
SourceLocation KindKwLoc;
1663+
1664+
/// Set kind of the clause.
1665+
///
1666+
/// \param K Kind of clause.
1667+
void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
1668+
1669+
/// Set clause kind location.
1670+
///
1671+
/// \param KLoc Kind location.
1672+
void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1673+
1674+
/// Sets the location of '('.
1675+
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1676+
1677+
public:
1678+
/// Build 'severity' clause with argument \a A ('fatal' or 'warning').
1679+
///
1680+
/// \param A Argument of the clause ('fatal' or 'warning').
1681+
/// \param ALoc Starting location of the argument.
1682+
/// \param StartLoc Starting location of the clause.
1683+
/// \param LParenLoc Location of '('.
1684+
/// \param EndLoc Ending location of the clause.
1685+
OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc,
1686+
SourceLocation StartLoc, SourceLocation LParenLoc,
1687+
SourceLocation EndLoc)
1688+
: OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
1689+
LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1690+
1691+
/// Build an empty clause.
1692+
OMPSeverityClause()
1693+
: OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
1694+
SourceLocation()) {}
1695+
1696+
/// Returns the locaiton of '('.
1697+
SourceLocation getLParenLoc() const { return LParenLoc; }
1698+
1699+
/// Returns kind of the clause.
1700+
OpenMPSeverityClauseKind getSeverityKind() const { return Kind; }
1701+
1702+
/// Returns location of clause kind.
1703+
SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
1704+
1705+
child_range children() {
1706+
return child_range(child_iterator(), child_iterator());
1707+
}
1708+
1709+
const_child_range children() const {
1710+
return const_child_range(const_child_iterator(), const_child_iterator());
1711+
}
1712+
1713+
child_range used_children() {
1714+
return child_range(child_iterator(), child_iterator());
1715+
}
1716+
const_child_range used_children() const {
1717+
return const_child_range(const_child_iterator(), const_child_iterator());
1718+
}
1719+
1720+
static bool classof(const OMPClause *T) {
1721+
return T->getClauseKind() == llvm::omp::OMPC_severity;
1722+
}
1723+
};
1724+
16451725
/// This represents 'schedule' clause in the '#pragma omp ...' directive.
16461726
///
16471727
/// \code

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,11 @@ bool RecursiveASTVisitor<Derived>::VisitOMPAtClause(OMPAtClause *) {
33153315
return true;
33163316
}
33173317

3318+
template <typename Derived>
3319+
bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) {
3320+
return true;
3321+
}
3322+
33183323
template <typename Derived>
33193324
bool
33203325
RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#ifndef OPENMP_AT_KIND
4545
#define OPENMP_AT_KIND(Name)
4646
#endif
47+
#ifndef OPENMP_SEVERITY_KIND
48+
#define OPENMP_SEVERITY_KIND(Name)
49+
#endif
4750
#ifndef OPENMP_DEFAULTMAP_MODIFIER
4851
#define OPENMP_DEFAULTMAP_MODIFIER(Name)
4952
#endif
@@ -126,6 +129,10 @@ OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(relaxed)
126129
OPENMP_AT_KIND(compilation)
127130
OPENMP_AT_KIND(execution)
128131

132+
// Modifiers for 'severity' clause.
133+
OPENMP_SEVERITY_KIND(fatal)
134+
OPENMP_SEVERITY_KIND(warning)
135+
129136
// Map types for 'map' clause.
130137
OPENMP_MAP_KIND(alloc)
131138
OPENMP_MAP_KIND(to)
@@ -187,6 +194,7 @@ OPENMP_BIND_KIND(thread)
187194
#undef OPENMP_SCHEDULE_KIND
188195
#undef OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND
189196
#undef OPENMP_AT_KIND
197+
#undef OPENMP_SEVERITY_KIND
190198
#undef OPENMP_MAP_KIND
191199
#undef OPENMP_MAP_MODIFIER_KIND
192200
#undef OPENMP_MOTION_MODIFIER_KIND

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ enum OpenMPAtClauseKind {
138138
OMPC_AT_unknown
139139
};
140140

141+
/// OpenMP attributes for 'severity' clause.
142+
enum OpenMPSeverityClauseKind {
143+
#define OPENMP_SEVERITY_KIND(Name) OMPC_SEVERITY_##Name,
144+
#include "clang/Basic/OpenMPKinds.def"
145+
OMPC_SEVERITY_unknown
146+
};
147+
141148
/// OpenMP device type for 'device_type' clause.
142149
enum OpenMPDeviceType {
143150
#define OPENMP_DEVICE_TYPE_KIND(Name) \

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11836,6 +11836,13 @@ class Sema final {
1183611836
SourceLocation LParenLoc,
1183711837
SourceLocation EndLoc);
1183811838

11839+
/// Called on well-formed 'severity' clause.
11840+
OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind,
11841+
SourceLocation KindLoc,
11842+
SourceLocation StartLoc,
11843+
SourceLocation LParenLoc,
11844+
SourceLocation EndLoc);
11845+
1183911846
/// Data used for processing a list of variables in OpenMP clauses.
1184011847
struct OpenMPVarListDataTy final {
1184111848
Expr *DepModOrTailExpr = nullptr;

clang/lib/AST/OpenMPClause.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
153153
case OMPC_dynamic_allocators:
154154
case OMPC_atomic_default_mem_order:
155155
case OMPC_at:
156+
case OMPC_severity:
156157
case OMPC_device_type:
157158
case OMPC_match:
158159
case OMPC_nontemporal:
@@ -253,6 +254,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
253254
case OMPC_dynamic_allocators:
254255
case OMPC_atomic_default_mem_order:
255256
case OMPC_at:
257+
case OMPC_severity:
256258
case OMPC_device_type:
257259
case OMPC_match:
258260
case OMPC_nontemporal:
@@ -1788,6 +1790,12 @@ void OMPClausePrinter::VisitOMPAtClause(OMPAtClause *Node) {
17881790
<< ")";
17891791
}
17901792

1793+
void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
1794+
OS << "severity("
1795+
<< getOpenMPSimpleClauseTypeName(OMPC_severity, Node->getSeverityKind())
1796+
<< ")";
1797+
}
1798+
17911799
void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
17921800
OS << "schedule(";
17931801
if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {

clang/lib/AST/StmtProfile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
532532

533533
void OMPClauseProfiler::VisitOMPAtClause(const OMPAtClause *C) {}
534534

535+
void OMPClauseProfiler::VisitOMPSeverityClause(const OMPSeverityClause *C) {}
536+
535537
void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
536538
VistOMPClauseWithPreInit(C);
537539
if (auto *S = C->getChunkSize())

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
109109
#define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
110110
#include "clang/Basic/OpenMPKinds.def"
111111
.Default(OMPC_AT_unknown);
112+
case OMPC_severity:
113+
return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
114+
#define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
115+
#include "clang/Basic/OpenMPKinds.def"
116+
.Default(OMPC_SEVERITY_unknown);
112117
case OMPC_lastprivate:
113118
return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
114119
#define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
@@ -351,7 +356,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
351356
#include "clang/Basic/OpenMPKinds.def"
352357
}
353358
llvm_unreachable("Invalid OpenMP 'at' clause type");
354-
llvm_unreachable("Invalid OpenMP 'at' clause type");
359+
case OMPC_severity:
360+
switch (Type) {
361+
case OMPC_SEVERITY_unknown:
362+
return "unknown";
363+
#define OPENMP_SEVERITY_KIND(Name) \
364+
case OMPC_SEVERITY_##Name: \
365+
return #Name;
366+
#include "clang/Basic/OpenMPKinds.def"
367+
}
368+
llvm_unreachable("Invalid OpenMP 'severity' clause type");
355369
case OMPC_lastprivate:
356370
switch (Type) {
357371
case OMPC_LASTPRIVATE_unknown:

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6513,6 +6513,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
65136513
case OMPC_dynamic_allocators:
65146514
case OMPC_atomic_default_mem_order:
65156515
case OMPC_at:
6516+
case OMPC_severity:
65166517
case OMPC_device_type:
65176518
case OMPC_match:
65186519
case OMPC_nontemporal:

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
32373237
case OMPC_proc_bind:
32383238
case OMPC_atomic_default_mem_order:
32393239
case OMPC_at:
3240+
case OMPC_severity:
32403241
case OMPC_order:
32413242
case OMPC_bind:
32423243
// OpenMP [2.14.3.1, Restrictions]
@@ -3247,8 +3248,9 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
32473248
// OpenMP [5.0, Requires directive, Restrictions]
32483249
// At most one atomic_default_mem_order clause can appear
32493250
// on the directive
3250-
// OpenMP [5.1, Requires directive, Restrictions]
3251+
// OpenMP [5.1, error directive, Restrictions]
32513252
// At most one at clause can appear on the directive
3253+
// At most one severity clause can appear on the directive
32523254
// OpenMP 5.1, 2.11.7 loop Construct, Restrictions.
32533255
// At most one bind clause can appear on a loop directive.
32543256
if (!FirstClause && CKind != OMPC_order) {

0 commit comments

Comments
 (0)