Skip to content

Commit 58448e3

Browse files
committed
Initial support for OmpSs-2 dependency syntax
Closes llvm#4
1 parent 133205d commit 58448e3

File tree

14 files changed

+215
-33
lines changed

14 files changed

+215
-33
lines changed

clang/include/clang/AST/OmpSsClause.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,24 +543,29 @@ class OSSDependClause final
543543
/// Colon location.
544544
SourceLocation ColonLoc;
545545

546+
/// OpenMP or OmpSs-2 syntax.
547+
bool OSSSyntax;
548+
546549
/// Build clause with number of variables \a N.
547550
///
548551
/// \param StartLoc Starting location of the clause.
549552
/// \param LParenLoc Location of '('.
550553
/// \param EndLoc Ending location of the clause.
551554
/// \param N Number of the variables in the clause.
552555
OSSDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
553-
SourceLocation EndLoc, unsigned N)
556+
SourceLocation EndLoc, unsigned N, bool OSSSyntax)
554557
: OSSVarListClause<OSSDependClause>(OSSC_depend, StartLoc, LParenLoc,
555-
EndLoc, N) {}
558+
EndLoc, N), OSSSyntax(OSSSyntax)
559+
{}
556560

557561
/// Build an empty clause.
558562
///
559563
/// \param N Number of variables.
560564
explicit OSSDependClause(unsigned N)
561565
: OSSVarListClause<OSSDependClause>(OSSC_depend, SourceLocation(),
562566
SourceLocation(), SourceLocation(),
563-
N), DepKinds(1, OSSC_DEPEND_unknown)
567+
N), DepKinds(1, OSSC_DEPEND_unknown),
568+
OSSSyntax(false)
564569
{}
565570

566571
/// Set dependency kind.
@@ -587,13 +592,15 @@ class OSSDependClause final
587592
/// \param DepLoc Location of the dependency type.
588593
/// \param ColonLoc Colon location.
589594
/// \param VL List of references to the variables.
595+
/// \param OSSSyntax True if it's an OmpSs-2 depend clause (i.e. weakin())
590596
/// clause.
591597
static OSSDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
592598
SourceLocation LParenLoc,
593599
SourceLocation EndLoc,
594600
ArrayRef<OmpSsDependClauseKind> DepKinds,
595601
SourceLocation DepLoc, SourceLocation ColonLoc,
596-
ArrayRef<Expr *> VL);
602+
ArrayRef<Expr *> VL,
603+
bool OSSSyntax);
597604

598605
/// Creates an empty clause with \a N variables.
599606
///
@@ -610,6 +617,8 @@ class OSSDependClause final
610617
/// Get colon location.
611618
SourceLocation getColonLoc() const { return ColonLoc; }
612619

620+
bool isOSSSyntax() const { return OSSSyntax; }
621+
613622
child_range children() {
614623
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
615624
reinterpret_cast<Stmt **>(varlist_end()));

clang/include/clang/Basic/OmpSsKinds.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#ifndef OMPSS_DEPEND_KIND
3131
#define OMPSS_DEPEND_KIND(Name)
3232
#endif
33+
#ifndef OMPSS_CLAUSE_ALIAS
34+
#define OMPSS_CLAUSE_ALIAS(Alias, Name)
35+
#endif
3336

3437
// OmpSs directives.
3538
OMPSS_DIRECTIVE(task)
@@ -54,6 +57,14 @@ OMPSS_DEPEND_KIND(out)
5457
OMPSS_DEPEND_KIND(inout)
5558
OMPSS_DEPEND_KIND(weak)
5659

60+
// OmpSs-2 'depend' syntax aliases
61+
OMPSS_CLAUSE_ALIAS(in, depend)
62+
OMPSS_CLAUSE_ALIAS(out, depend)
63+
OMPSS_CLAUSE_ALIAS(inout, depend)
64+
OMPSS_CLAUSE_ALIAS(weakin, depend)
65+
OMPSS_CLAUSE_ALIAS(weakout, depend)
66+
OMPSS_CLAUSE_ALIAS(weakinout, depend)
67+
5768
// Clauses allowed for OmpSs directive 'task'.
5869
OMPSS_TASK_CLAUSE(if)
5970
OMPSS_TASK_CLAUSE(final)
@@ -62,10 +73,17 @@ OMPSS_TASK_CLAUSE(private)
6273
OMPSS_TASK_CLAUSE(firstprivate)
6374
OMPSS_TASK_CLAUSE(shared)
6475
OMPSS_TASK_CLAUSE(depend)
76+
OMPSS_TASK_CLAUSE(in)
77+
OMPSS_TASK_CLAUSE(out)
78+
OMPSS_TASK_CLAUSE(inout)
79+
OMPSS_TASK_CLAUSE(weakin)
80+
OMPSS_TASK_CLAUSE(weakout)
81+
OMPSS_TASK_CLAUSE(weakinout)
6582

6683
#undef OMPSS_DEPEND_KIND
6784
#undef OMPSS_DEFAULT_KIND
6885
#undef OMPSS_DIRECTIVE
6986
#undef OMPSS_DIRECTIVE_EXT
87+
#undef OMPSS_CLAUSE_ALIAS
7088
#undef OMPSS_CLAUSE
7189
#undef OMPSS_TASK_CLAUSE

clang/include/clang/Basic/OmpSsKinds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ enum OmpSsDirectiveKind {
3333
enum OmpSsClauseKind {
3434
#define OMPSS_CLAUSE(Name, Class) \
3535
OSSC_##Name,
36+
#define OMPSS_CLAUSE_ALIAS(Alias, Name) \
37+
OSSC_##Alias,
3638
#include "clang/Basic/OmpSsKinds.def"
3739
OSSC_unknown
3840
};

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9969,7 +9969,7 @@ class Sema {
99699969
ActOnOmpSsDependClause(ArrayRef<OmpSsDependClauseKind> DepKinds, SourceLocation DepLoc,
99709970
SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
99719971
SourceLocation StartLoc, SourceLocation LParenLoc,
9972-
SourceLocation EndLoc);
9972+
SourceLocation EndLoc, bool OSSSyntax = false);
99739973

99749974
OSSClause *ActOnOmpSsSingleExprClause(OmpSsClauseKind Kind,
99759975
Expr *Expr,

clang/lib/AST/OmpSsClause.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ OSSDependClause *
9090
OSSDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
9191
SourceLocation LParenLoc, SourceLocation EndLoc,
9292
ArrayRef<OmpSsDependClauseKind> DepKinds, SourceLocation DepLoc,
93-
SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
93+
SourceLocation ColonLoc, ArrayRef<Expr *> VL,
94+
bool OSSSyntax) {
9495
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
9596
OSSDependClause *Clause = new (Mem)
96-
OSSDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
97+
OSSDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), OSSSyntax);
9798
Clause->setVarRefs(VL);
9899
Clause->setDependencyKinds(DepKinds);
99100
Clause->setDependencyLoc(DepLoc);

clang/lib/AST/StmtPrinter.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,19 +720,27 @@ void OSSClausePrinter::VisitOSSSharedClause(OSSSharedClause *Node) {
720720
}
721721

722722
void OSSClausePrinter::VisitOSSDependClause(OSSDependClause *Node) {
723-
OS << "depend(";
724-
OS << getOmpSsSimpleClauseTypeName(Node->getClauseKind(),
725-
Node->getDependencyKind()[0]);
726-
if (Node->getDependencyKind().size() == 2) {
727-
OS << " ,";
723+
if (Node->isOSSSyntax()) {
728724
OS << getOmpSsSimpleClauseTypeName(Node->getClauseKind(),
729-
Node->getDependencyKind()[1]);
725+
Node->getDependencyKind()[0]);
726+
if (!Node->varlist_empty()) {
727+
VisitOSSClauseList(Node, '(');
728+
}
729+
} else {
730+
OS << "depend(";
731+
OS << getOmpSsSimpleClauseTypeName(Node->getClauseKind(),
732+
Node->getDependencyKind()[0]);
733+
if (Node->getDependencyKind().size() == 2) {
734+
OS << " ,";
735+
OS << getOmpSsSimpleClauseTypeName(Node->getClauseKind(),
736+
Node->getDependencyKind()[1]);
737+
}
738+
if (!Node->varlist_empty()) {
739+
OS << " :";
740+
VisitOSSClauseList(Node, ' ');
741+
}
730742
}
731743

732-
if (!Node->varlist_empty()) {
733-
OS << " :";
734-
VisitOSSClauseList(Node, ' ');
735-
}
736744
OS << ")";
737745
}
738746

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ void TextNodeDumper::Visit(const OSSClause *C) {
337337
dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
338338
if (C->isImplicit())
339339
OS << " <implicit>";
340+
341+
if (const OSSDependClause *DC = dyn_cast<OSSDependClause>(C)) {
342+
if (DC->isOSSSyntax())
343+
OS << " <oss syntax>";
344+
}
340345
}
341346

342347
void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {

clang/lib/Basic/OmpSsKinds.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const char *clang::getOmpSsDirectiveName(OmpSsDirectiveKind Kind) {
4848
OmpSsClauseKind clang::getOmpSsClauseKind(StringRef Str) {
4949
return llvm::StringSwitch<OmpSsClauseKind>(Str)
5050
#define OMPSS_CLAUSE(Name, Class) .Case(#Name, OSSC_##Name)
51+
#define OMPSS_CLAUSE_ALIAS(Alias, Name) .Case(#Alias, OSSC_##Alias)
5152
#include "clang/Basic/OmpSsKinds.def"
5253
.Default(OSSC_unknown);
5354
}
@@ -60,6 +61,9 @@ const char *clang::getOmpSsClauseName(OmpSsClauseKind Kind) {
6061
#define OMPSS_CLAUSE(Name, Class) \
6162
case OSSC_##Name: \
6263
return #Name;
64+
#define OMPSS_CLAUSE_ALIAS(Alias, Name) \
65+
case OSSC_##Alias: \
66+
return #Alias;
6367
#include "clang/Basic/OmpSsKinds.def"
6468
}
6569
llvm_unreachable("Invalid OmpSs clause kind");

clang/lib/Parse/ParseOmpSs.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ StmtResult Parser::ParseOmpSsDeclarativeOrExecutableDirective(
124124
/// clause:
125125
/// depend-clause | if-clause | final-clause
126126
/// | default-clause | shared-clause | private-clause
127-
/// | firstprivate-clause
127+
/// | firstprivate-clause | in-clause | out-clause
128+
/// | inout-clause | weakin-clause | weakout-clause
129+
/// | weakinout-clause
128130
///
129131
OSSClause *Parser::ParseOmpSsClause(OmpSsDirectiveKind DKind,
130-
OmpSsClauseKind CKind, bool FirstClause) {
132+
OmpSsClauseKind CKind, bool FirstClause) {
131133
OSSClause *Clause = nullptr;
132134
bool ErrorFound = false;
133135
bool WrongDirective = false;
@@ -162,6 +164,12 @@ OSSClause *Parser::ParseOmpSsClause(OmpSsDirectiveKind DKind,
162164
case OSSC_private:
163165
case OSSC_firstprivate:
164166
case OSSC_depend:
167+
case OSSC_in:
168+
case OSSC_out:
169+
case OSSC_inout:
170+
case OSSC_weakin:
171+
case OSSC_weakout:
172+
case OSSC_weakinout:
165173
Clause = ParseOmpSsVarListClause(DKind, CKind, WrongDirective);
166174
break;
167175
case OSSC_unknown:
@@ -175,9 +183,9 @@ OSSClause *Parser::ParseOmpSsClause(OmpSsDirectiveKind DKind,
175183

176184
/// Parses clauses with list.
177185
bool Parser::ParseOmpSsVarList(OmpSsDirectiveKind DKind,
178-
OmpSsClauseKind Kind,
179-
SmallVectorImpl<Expr *> &Vars,
180-
OmpSsVarListDataTy &Data) {
186+
OmpSsClauseKind Kind,
187+
SmallVectorImpl<Expr *> &Vars,
188+
OmpSsVarListDataTy &Data) {
181189
// Parse '('.
182190
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_ompss_end);
183191
if (T.expectAndConsume(diag::err_expected_lparen_after,
@@ -228,9 +236,14 @@ bool Parser::ParseOmpSsVarList(OmpSsDirectiveKind DKind,
228236
Data.DepKinds.end(),
229237
OSSC_DEPEND_unknown);
230238

239+
// IsComma init determine if we got a well-formed clause
231240
bool IsComma = (Kind != OSSC_depend)
232241
|| (Kind == OSSC_depend && DepKindIt == Data.DepKinds.end());
233-
242+
// We parse the locator-list when:
243+
// 1. If we found out something that seems a valid item regardless
244+
// of the clause validity
245+
// 2. We got a well-formed clause regardless what comes next.
246+
// while (IsComma || Tok.looks_like_valid_item)
234247
while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
235248
Tok.isNot(tok::annot_pragma_ompss_end))) {
236249
// Parse variable
@@ -256,9 +269,10 @@ bool Parser::ParseOmpSsVarList(OmpSsDirectiveKind DKind,
256269
Data.RLoc = Tok.getLocation();
257270
if (!T.consumeClose())
258271
Data.RLoc = T.getCloseLocation();
272+
// return Well-formed clause but empty list
259273
return (Kind == OSSC_depend
260-
&& DepKindIt == Data.DepKinds.end()
261-
&& Vars.empty());
274+
&& DepKindIt == Data.DepKinds.end() && Vars.empty())
275+
|| (Kind != OSSC_depend && Vars.empty());
262276
}
263277

264278
/// Parsing of OmpSs
@@ -272,6 +286,18 @@ bool Parser::ParseOmpSsVarList(OmpSsDirectiveKind DKind,
272286
/// 'firstprivate' '(' list ')'
273287
/// shared-clause:
274288
/// 'shared' '(' list ')'
289+
/// in-clause:
290+
/// 'in' '(' list ')'
291+
/// out-clause:
292+
/// 'out' '(' list ')'
293+
/// inout-clause:
294+
/// 'inout' '(' list ')'
295+
/// weakin-clause:
296+
/// 'weakin' '(' list ')'
297+
/// weakout-clause:
298+
/// 'weakout' '(' list ')'
299+
/// weakinout-clause:
300+
/// 'weakinout' '(' list ')'
275301
OSSClause *Parser::ParseOmpSsVarListClause(OmpSsDirectiveKind DKind,
276302
OmpSsClauseKind Kind,
277303
bool ParseOnly) {
@@ -280,7 +306,10 @@ OSSClause *Parser::ParseOmpSsVarListClause(OmpSsDirectiveKind DKind,
280306
SmallVector<Expr *, 4> Vars;
281307
OmpSsVarListDataTy Data;
282308

283-
Actions.AllowShapings = (Kind == OSSC_depend);
309+
Actions.AllowShapings =
310+
(Kind == OSSC_depend
311+
|| Kind == OSSC_in || Kind == OSSC_out || Kind == OSSC_inout
312+
|| Kind == OSSC_weakin || Kind == OSSC_weakout || Kind == OSSC_weakinout);
284313

285314
if (ParseOmpSsVarList(DKind, Kind, Vars, Data)) {
286315
Actions.AllowShapings = false;

clang/lib/Sema/SemaOmpSs.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ OSSClause *
759759
Sema::ActOnOmpSsDependClause(ArrayRef<OmpSsDependClauseKind> DepKinds, SourceLocation DepLoc,
760760
SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
761761
SourceLocation StartLoc,
762-
SourceLocation LParenLoc, SourceLocation EndLoc) {
762+
SourceLocation LParenLoc, SourceLocation EndLoc,
763+
bool OSSSyntax) {
763764
if (DepKinds.size() == 2) {
764765
int numWeaks = 0;
765766
int numUnk = 0;
@@ -821,7 +822,8 @@ Sema::ActOnOmpSsDependClause(ArrayRef<OmpSsDependClauseKind> DepKinds, SourceLoc
821822
}
822823
}
823824
return OSSDependClause::Create(Context, StartLoc, LParenLoc, EndLoc,
824-
DepKinds, DepLoc, ColonLoc, VarList);
825+
DepKinds, DepLoc, ColonLoc, VarList,
826+
OSSSyntax);
825827
}
826828

827829
OSSClause *
@@ -846,6 +848,33 @@ Sema::ActOnOmpSsVarListClause(
846848
Res = ActOnOmpSsDependClause(DepKinds, DepLoc, ColonLoc, Vars,
847849
StartLoc, LParenLoc, EndLoc);
848850
break;
851+
case OSSC_in:
852+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_in }, DepLoc, ColonLoc, Vars,
853+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
854+
break;
855+
case OSSC_out:
856+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_out }, DepLoc, ColonLoc, Vars,
857+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
858+
break;
859+
case OSSC_inout:
860+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_inout }, DepLoc, ColonLoc, Vars,
861+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
862+
break;
863+
case OSSC_weakin:
864+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_in, OSSC_DEPEND_weak },
865+
DepLoc, ColonLoc, Vars,
866+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
867+
break;
868+
case OSSC_weakout:
869+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_out, OSSC_DEPEND_weak },
870+
DepLoc, ColonLoc, Vars,
871+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
872+
break;
873+
case OSSC_weakinout:
874+
Res = ActOnOmpSsDependClause({ OSSC_DEPEND_inout, OSSC_DEPEND_weak },
875+
DepLoc, ColonLoc, Vars,
876+
StartLoc, LParenLoc, EndLoc, /*OSSSyntax=*/true);
877+
break;
849878
default:
850879
llvm_unreachable("Clause is not allowed.");
851880
}

clang/lib/Sema/TreeTransform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,9 @@ class TreeTransform {
15711571
RebuildOSSDependClause(ArrayRef<OmpSsDependClauseKind> DepKinds, SourceLocation DepLoc,
15721572
SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
15731573
SourceLocation StartLoc, SourceLocation LParenLoc,
1574-
SourceLocation EndLoc) {
1574+
SourceLocation EndLoc, bool OSSSyntax) {
15751575
return getSema().ActOnOmpSsDependClause(DepKinds, DepLoc, ColonLoc, VarList,
1576-
StartLoc, LParenLoc, EndLoc);
1576+
StartLoc, LParenLoc, EndLoc, OSSSyntax);
15771577
}
15781578

15791579
/// Build a new OmpSs 'shared' clause.
@@ -9432,7 +9432,7 @@ TreeTransform<Derived>::TransformOSSDependClause(OSSDependClause *C) {
94329432

94339433
return getDerived().RebuildOSSDependClause(
94349434
C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
9435-
C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9435+
C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc(), C->isOSSSyntax());
94369436
}
94379437

94389438
template <typename Derived>

clang/test/OmpSs/AST/task_depend.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,18 @@ void foo5(int *p, int n) {
275275
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:49> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
276276
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:36> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
277277

278+
void foo6(int *p, int n) {
279+
#pragma oss task in(p) out(n)
280+
{}
281+
}
282+
283+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:279:13, col:34>
284+
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:22, col:26> <oss syntax>
285+
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:25> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
286+
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:28, col:33> <oss syntax>
287+
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:32> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
288+
// CHECK-NEXT: OSSFirstprivateClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
289+
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:25> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
290+
// CHECK-NEXT: OSSSharedClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
291+
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:32> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
292+

0 commit comments

Comments
 (0)