Skip to content

Commit ef57977

Browse files
committed
Support for weakcommutative clause
- Improved task outline clause diagnostic. Introduced a new directive kind to define task outline supported clauses. - Added support for weakcommutative and weakconcurrent both in LLVM and Clang. Currently there is no support for weakconcurrent so we emit a diagnostic error for them. - Now OpenMP concurrent/commutative depend kinds are right. Fixes llvm#57, llvm#66
1 parent 6559fcc commit ef57977

22 files changed

+347
-113
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,12 +3138,14 @@ def OSSTaskDecl : Attr {
31383138
VariadicExprArgument<"Concurrents">, VariadicExprArgument<"Commutatives">,
31393139
VariadicExprArgument<"WeakIns">, VariadicExprArgument<"WeakOuts">,
31403140
VariadicExprArgument<"WeakInouts">,
3141+
VariadicExprArgument<"WeakConcurrents">, VariadicExprArgument<"WeakCommutatives">,
31413142
// depend(in : )
31423143
VariadicExprArgument<"DepIns">, VariadicExprArgument<"DepOuts">,
31433144
VariadicExprArgument<"DepInouts">,
31443145
VariadicExprArgument<"DepConcurrents">, VariadicExprArgument<"DepCommutatives">,
31453146
VariadicExprArgument<"DepWeakIns">, VariadicExprArgument<"DepWeakOuts">,
3146-
VariadicExprArgument<"DepWeakInouts">
3147+
VariadicExprArgument<"DepWeakInouts">,
3148+
VariadicExprArgument<"DepWeakConcurrents">, VariadicExprArgument<"DepWeakCommutatives">
31473149
];
31483150
let AdditionalMembers = [{
31493151
void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
@@ -3170,14 +3172,18 @@ def OSSTaskDecl : Attr {
31703172
l("weakin", "(", weakIns_size(), weakIns_begin(), weakIns_end(), OS, Policy);
31713173
l("weakout", "(", weakOuts_size(), weakOuts_begin(), weakOuts_end(), OS, Policy);
31723174
l("weakinout", "(", weakInouts_size(), weakInouts_begin(), weakInouts_end(), OS, Policy);
3175+
l("weakconcurrent", "(", weakConcurrents_size(), weakConcurrents_begin(), weakConcurrents_end(), OS, Policy);
3176+
l("weakcommutative", "(", weakCommutatives_size(), weakCommutatives_begin(), weakCommutatives_end(), OS, Policy);
31733177
l("depend(in", ":", depIns_size(), depIns_begin(), depIns_end(), OS, Policy);
31743178
l("depend(out", ":", depOuts_size(), depOuts_begin(), depOuts_end(), OS, Policy);
31753179
l("depend(inout", ":", depInouts_size(), depInouts_begin(), depInouts_end(), OS, Policy);
3176-
l("depend(mutexinoutset", ":", depConcurrents_size(), depConcurrents_begin(), depConcurrents_end(), OS, Policy);
3177-
l("depend(inoutset", ":", depCommutatives_size(), depCommutatives_begin(), depCommutatives_end(), OS, Policy);
3180+
l("depend(inoutset", ":", depConcurrents_size(), depConcurrents_begin(), depConcurrents_end(), OS, Policy);
3181+
l("depend(mutexinoutset", ":", depCommutatives_size(), depCommutatives_begin(), depCommutatives_end(), OS, Policy);
31783182
l("depend(weak, in", ":", depWeakIns_size(), depWeakIns_begin(), depWeakIns_end(), OS, Policy);
31793183
l("depend(weak, out", ":", depWeakOuts_size(), depWeakOuts_begin(), depWeakOuts_end(), OS, Policy);
31803184
l("depend(weak, inout", ":", depWeakInouts_size(), depWeakInouts_begin(), depWeakInouts_end(), OS, Policy);
3185+
l("depend(weak, inoutset", ":", depWeakConcurrents_size(), depWeakConcurrents_begin(), depWeakConcurrents_end(), OS, Policy);
3186+
l("depend(weak, mutexinoutset", ":", depWeakCommutatives_size(), depWeakCommutatives_begin(), depWeakCommutatives_end(), OS, Policy);
31813187
if (auto *E = getIfExpr()) {
31823188
OS << " if(";
31833189
E->printPretty(OS, nullptr, Policy);

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9878,7 +9878,7 @@ def err_oss_unexpected_clause_value : Error<
98789878
def err_oss_depend_weak_required : Error<
98799879
"expected 'weak' dependency type">;
98809880
def err_oss_depend_no_weak_compatible : Error<
9881-
"dependency types %0 cannot be combined with others">;
9881+
"dependency type%s1 %0 cannot be combined with others">;
98829882
def err_oss_wrong_dsa : Error<
98839883
"%0 variable cannot be %1">;
98849884
def err_oss_array_section_use : Error<"OmpSs-2 array section is not allowed here">;

clang/include/clang/Basic/OmpSsKinds.def

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#ifndef OMPSS_TASK_CLAUSE
2525
# define OMPSS_TASK_CLAUSE(Name)
2626
#endif
27+
#ifndef OMPSS_DECLARE_TASK_CLAUSE
28+
# define OMPSS_DECLARE_TASK_CLAUSE(Name)
29+
#endif
2730
#ifndef OMPSS_DEFAULT_KIND
2831
# define OMPSS_DEFAULT_KIND(Name)
2932
#endif
@@ -50,6 +53,7 @@ OMPSS_CLAUSE(shared, OSSSharedClause)
5053
OMPSS_CLAUSE(depend, OSSDependClause)
5154
OMPSS_CLAUSE(reduction, OSSReductionClause)
5255
OMPSS_DIRECTIVE_EXT(declare_reduction, "declare reduction")
56+
OMPSS_DIRECTIVE_EXT(declare_task, "task")
5357

5458
// Static attributes for 'default' clause.
5559
OMPSS_DEFAULT_KIND(none)
@@ -60,9 +64,9 @@ OMPSS_DEPEND_KIND(in)
6064
OMPSS_DEPEND_KIND(out)
6165
OMPSS_DEPEND_KIND(inout)
6266
// Concurrent
63-
OMPSS_DEPEND_KIND(mutexinoutset)
64-
// Commutative
6567
OMPSS_DEPEND_KIND(inoutset)
68+
// Commutative
69+
OMPSS_DEPEND_KIND(mutexinoutset)
6670
OMPSS_DEPEND_KIND(weak)
6771

6872
// OmpSs-2 'depend' syntax aliases
@@ -74,6 +78,8 @@ OMPSS_CLAUSE_ALIAS(commutative, depend)
7478
OMPSS_CLAUSE_ALIAS(weakin, depend)
7579
OMPSS_CLAUSE_ALIAS(weakout, depend)
7680
OMPSS_CLAUSE_ALIAS(weakinout, depend)
81+
OMPSS_CLAUSE_ALIAS(weakconcurrent, depend)
82+
OMPSS_CLAUSE_ALIAS(weakcommutative, depend)
7783
// OmpSs-2 'reduction' alias
7884
OMPSS_CLAUSE_ALIAS(weakreduction, reduction)
7985

@@ -96,12 +102,30 @@ OMPSS_TASK_CLAUSE(commutative)
96102
OMPSS_TASK_CLAUSE(weakin)
97103
OMPSS_TASK_CLAUSE(weakout)
98104
OMPSS_TASK_CLAUSE(weakinout)
105+
OMPSS_TASK_CLAUSE(weakcommutative)
99106
OMPSS_TASK_CLAUSE(weakreduction)
100107

108+
// Clauses allowed for OmpSs directive 'task' declaration/outline.
109+
OMPSS_DECLARE_TASK_CLAUSE(if)
110+
OMPSS_DECLARE_TASK_CLAUSE(final)
111+
OMPSS_DECLARE_TASK_CLAUSE(cost)
112+
OMPSS_DECLARE_TASK_CLAUSE(priority)
113+
OMPSS_DECLARE_TASK_CLAUSE(depend)
114+
OMPSS_DECLARE_TASK_CLAUSE(in)
115+
OMPSS_DECLARE_TASK_CLAUSE(out)
116+
OMPSS_DECLARE_TASK_CLAUSE(inout)
117+
OMPSS_DECLARE_TASK_CLAUSE(concurrent)
118+
OMPSS_DECLARE_TASK_CLAUSE(commutative)
119+
OMPSS_DECLARE_TASK_CLAUSE(weakin)
120+
OMPSS_DECLARE_TASK_CLAUSE(weakout)
121+
OMPSS_DECLARE_TASK_CLAUSE(weakinout)
122+
OMPSS_DECLARE_TASK_CLAUSE(weakcommutative)
123+
101124
#undef OMPSS_DEPEND_KIND
102125
#undef OMPSS_DEFAULT_KIND
103126
#undef OMPSS_DIRECTIVE
104127
#undef OMPSS_DIRECTIVE_EXT
105128
#undef OMPSS_CLAUSE_ALIAS
106129
#undef OMPSS_CLAUSE
130+
#undef OMPSS_DECLARE_TASK_CLAUSE
107131
#undef OMPSS_TASK_CLAUSE

clang/include/clang/Parse/Parser.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,18 @@ class Parser : public CodeCompletionHandler {
28942894
/// \param RLoc Returned location of right paren.
28952895
ExprResult ParseOmpSsParensExpr(StringRef ClauseName, SourceLocation &RLoc);
28962896

2897+
/// Data used for parsing simple clause.
2898+
struct OmpSsSimpleClauseDataTy {
2899+
unsigned Type;
2900+
SourceLocation TypeLoc;
2901+
SourceLocation LOpen;
2902+
SourceLocation Loc;
2903+
SourceLocation RLoc;
2904+
};
2905+
/// Parses simple clauses, like 'default'.
2906+
bool ParseOmpSsSimpleClauseImpl(OmpSsClauseKind Kind,
2907+
OmpSsSimpleClauseDataTy &Data);
2908+
28972909
/// Data used for parsing list of variables in OmpSs clauses.
28982910
struct OmpSsVarListDataTy {
28992911
SourceLocation ColonLoc;

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9979,10 +9979,13 @@ class Sema {
99799979
ArrayRef<Expr *> Concurrents, ArrayRef<Expr *> Commutatives,
99809980
ArrayRef<Expr *> WeakIns, ArrayRef<Expr *> WeakOuts,
99819981
ArrayRef<Expr *> WeakInouts,
9982+
ArrayRef<Expr *> WeakConcurrents, ArrayRef<Expr *> WeakCommutatives,
99829983
ArrayRef<Expr *> DepIns, ArrayRef<Expr *> DepOuts, ArrayRef<Expr *> DepInouts,
99839984
ArrayRef<Expr *> DepConcurrents, ArrayRef<Expr *> DepCommutatives,
99849985
ArrayRef<Expr *> DepWeakIns, ArrayRef<Expr *> DepWeakOuts,
9985-
ArrayRef<Expr *> DepWeakInouts, SourceRange SR);
9986+
ArrayRef<Expr *> DepWeakInouts,
9987+
ArrayRef<Expr *> DepWeakConcurrents, ArrayRef<Expr *> DepWeakCommutatives,
9988+
SourceRange SR);
99869989

99879990
OSSClause *ActOnOmpSsVarListClause(
99889991
OmpSsClauseKind Kind, ArrayRef<Expr *> Vars,

clang/lib/Basic/OmpSsKinds.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ unsigned clang::getOmpSsSimpleClauseType(OmpSsClauseKind Kind,
9999
case OSSC_weakin:
100100
case OSSC_weakout:
101101
case OSSC_weakinout:
102+
case OSSC_weakconcurrent:
103+
case OSSC_weakcommutative:
102104
case OSSC_weakreduction:
103105
break;
104106
}
@@ -145,6 +147,8 @@ const char *clang::getOmpSsSimpleClauseTypeName(OmpSsClauseKind Kind,
145147
case OSSC_weakin:
146148
case OSSC_weakout:
147149
case OSSC_weakinout:
150+
case OSSC_weakconcurrent:
151+
case OSSC_weakcommutative:
148152
case OSSC_weakreduction:
149153
break;
150154
}
@@ -161,6 +165,16 @@ bool clang::isAllowedClauseForDirective(OmpSsDirectiveKind DKind,
161165
#define OMPSS_TASK_CLAUSE(Name) \
162166
case OSSC_##Name: \
163167
return true;
168+
#include "clang/Basic/OmpSsKinds.def"
169+
default:
170+
break;
171+
}
172+
break;
173+
case OSSD_declare_task:
174+
switch (CKind) {
175+
#define OMPSS_DECLARE_TASK_CLAUSE(Name) \
176+
case OSSC_##Name: \
177+
return true;
164178
#include "clang/Basic/OmpSsKinds.def"
165179
default:
166180
break;

clang/lib/CodeGen/CGOmpSsRuntime.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,18 @@ RValue CGOmpSsRuntime::emitTaskFunction(CodeGenFunction &CGF,
19771977
Dep.E = E;
19781978
EmitDependency("QUAL.OSS.DEP.WEAKINOUT", CGF, Dep, TaskInfo, CaptureMapStack);
19791979
}
1980+
for (const Expr *E : Attr->weakConcurrents()) {
1981+
OSSDepDataTy Dep;
1982+
Dep.OSSSyntax = true;
1983+
Dep.E = E;
1984+
EmitDependency("QUAL.OSS.DEP.WEAKCONCURRENT", CGF, Dep, TaskInfo, CaptureMapStack);
1985+
}
1986+
for (const Expr *E : Attr->weakCommutatives()) {
1987+
OSSDepDataTy Dep;
1988+
Dep.OSSSyntax = true;
1989+
Dep.E = E;
1990+
EmitDependency("QUAL.OSS.DEP.WEAKCOMMUTATIVE", CGF, Dep, TaskInfo, CaptureMapStack);
1991+
}
19801992
// depend(in :)
19811993
for (const Expr *E : Attr->depIns()) {
19821994
OSSDepDataTy Dep;
@@ -2026,6 +2038,18 @@ RValue CGOmpSsRuntime::emitTaskFunction(CodeGenFunction &CGF,
20262038
Dep.E = E;
20272039
EmitDependency("QUAL.OSS.DEP.WEAKINOUT", CGF, Dep, TaskInfo, CaptureMapStack);
20282040
}
2041+
for (const Expr *E : Attr->depWeakConcurrents()) {
2042+
OSSDepDataTy Dep;
2043+
Dep.OSSSyntax = false;
2044+
Dep.E = E;
2045+
EmitDependency("QUAL.OSS.DEP.WEAKCONCURRENT", CGF, Dep, TaskInfo, CaptureMapStack);
2046+
}
2047+
for (const Expr *E : Attr->depWeakCommutatives()) {
2048+
OSSDepDataTy Dep;
2049+
Dep.OSSSyntax = false;
2050+
Dep.E = E;
2051+
EmitDependency("QUAL.OSS.DEP.WEAKCOMMUTATIVE", CGF, Dep, TaskInfo, CaptureMapStack);
2052+
}
20292053
if (!CapturedList.empty())
20302054
TaskInfo.emplace_back("QUAL.OSS.CAPTURED", CapturedList);
20312055
}
@@ -2144,6 +2168,12 @@ void CGOmpSsRuntime::emitTaskCall(CodeGenFunction &CGF,
21442168
for (const OSSDepDataTy &Dep : Data.Deps.WeakInouts) {
21452169
EmitDependency("QUAL.OSS.DEP.WEAKINOUT", CGF, Dep, TaskInfo, CaptureMapStack);
21462170
}
2171+
for (const OSSDepDataTy &Dep : Data.Deps.WeakConcurrents) {
2172+
EmitDependency("QUAL.OSS.DEP.WEAKCONCURRENT", CGF, Dep, TaskInfo, CaptureMapStack);
2173+
}
2174+
for (const OSSDepDataTy &Dep : Data.Deps.WeakCommutatives) {
2175+
EmitDependency("QUAL.OSS.DEP.WEAKCOMMUTATIVE", CGF, Dep, TaskInfo, CaptureMapStack);
2176+
}
21472177
for (const OSSReductionDataTy &Red : Data.Reductions.RedList) {
21482178
EmitReduction("QUAL.OSS.DEP.REDUCTION",
21492179
"QUAL.OSS.DEP.REDUCTION.INIT",

clang/lib/CodeGen/CGOmpSsRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct OSSTaskDepDataTy final {
6262
SmallVector<OSSDepDataTy, 4> Ins;
6363
SmallVector<OSSDepDataTy, 4> Outs;
6464
SmallVector<OSSDepDataTy, 4> Inouts;
65+
SmallVector<OSSDepDataTy, 4> WeakConcurrents;
66+
SmallVector<OSSDepDataTy, 4> WeakCommutatives;
6567
SmallVector<OSSDepDataTy, 4> Concurrents;
6668
SmallVector<OSSDepDataTy, 4> Commutatives;
6769
};

clang/lib/CodeGen/CGStmtOmpSs.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ static void AddDepData(const OSSTaskDirective &S, OSSTaskDepDataTy &Deps) {
9797
Deps.WeakOuts.push_back({C->isOSSSyntax(), Ref});
9898
if (DepKindsOrdered[0] == OSSC_DEPEND_inout)
9999
Deps.WeakInouts.push_back({C->isOSSSyntax(), Ref});
100+
if (DepKindsOrdered[0] == OSSC_DEPEND_inoutset)
101+
Deps.WeakConcurrents.push_back({C->isOSSSyntax(), Ref});
102+
if (DepKindsOrdered[0] == OSSC_DEPEND_mutexinoutset)
103+
Deps.WeakCommutatives.push_back({C->isOSSSyntax(), Ref});
100104
}
101105
}
102106
else {
@@ -107,9 +111,9 @@ static void AddDepData(const OSSTaskDirective &S, OSSTaskDepDataTy &Deps) {
107111
Deps.Outs.push_back({C->isOSSSyntax(), Ref});
108112
if (DepKindsOrdered[0] == OSSC_DEPEND_inout)
109113
Deps.Inouts.push_back({C->isOSSSyntax(), Ref});
110-
if (DepKindsOrdered[0] == OSSC_DEPEND_mutexinoutset)
111-
Deps.Concurrents.push_back({C->isOSSSyntax(), Ref});
112114
if (DepKindsOrdered[0] == OSSC_DEPEND_inoutset)
115+
Deps.Concurrents.push_back({C->isOSSSyntax(), Ref});
116+
if (DepKindsOrdered[0] == OSSC_DEPEND_mutexinoutset)
113117
Deps.Commutatives.push_back({C->isOSSSyntax(), Ref});
114118
}
115119
}

0 commit comments

Comments
 (0)