Skip to content

Commit b2af2b8

Browse files
committed
Add support for 'if' and 'final' clauses
- Simplified OpenMP based OSSIfClause class since we only care about the condition expr. - A bit of refactor in Codegen data structures - Added -disable-llvm-passes in IR tests to avoid the lowering Closes llvm#33
1 parent f97b53b commit b2af2b8

24 files changed

+302
-96
lines changed

clang/include/clang/AST/OmpSsClause.h

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ template <class T> class OSSVarListClause : public OSSClause {
233233
/// This represents 'if' clause in the '#pragma omp ...' directive.
234234
///
235235
/// \code
236-
/// #pragma omp parallel if(parallel:a > 5)
236+
/// #pragma omp task if(a > 5)
237237
/// \endcode
238-
/// In this example directive '#pragma omp parallel' has simple 'if' clause with
239-
/// condition 'a > 5' and directive name modifier 'parallel'.
240-
class OSSIfClause : public OSSClause, public OSSClauseWithPreInit {
238+
/// In this example directive '#pragma omp task' has simple 'if'
239+
/// clause with condition 'a > 5'.
240+
class OSSIfClause : public OSSClause {
241241
friend class OSSClauseReader;
242242

243243
/// Location of '('.
@@ -246,73 +246,34 @@ class OSSIfClause : public OSSClause, public OSSClauseWithPreInit {
246246
/// Condition of the 'if' clause.
247247
Stmt *Condition = nullptr;
248248

249-
/// Location of ':' (if any).
250-
SourceLocation ColonLoc;
251-
252-
/// Directive name modifier for the clause.
253-
OmpSsDirectiveKind NameModifier = OSSD_unknown;
254-
255-
/// Name modifier location.
256-
SourceLocation NameModifierLoc;
257-
258249
/// Set condition.
259250
void setCondition(Expr *Cond) { Condition = Cond; }
260251

261-
/// Set directive name modifier for the clause.
262-
void setNameModifier(OmpSsDirectiveKind NM) { NameModifier = NM; }
263-
264-
/// Set location of directive name modifier for the clause.
265-
void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
266-
267-
/// Set location of ':'.
268-
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
269-
270252
public:
271253
/// Build 'if' clause with condition \a Cond.
272254
///
273-
/// \param NameModifier [OmpSs 4.1] Directive name modifier of clause.
274-
/// \param Cond Condition of the clause.
275-
/// \param HelperCond Helper condition for the clause.
276-
/// \param CaptureRegion Innermost OmpSs region where expressions in this
277-
/// clause must be captured.
278255
/// \param StartLoc Starting location of the clause.
279256
/// \param LParenLoc Location of '('.
280-
/// \param NameModifierLoc Location of directive name modifier.
281-
/// \param ColonLoc [OmpSs 4.1] Location of ':'.
257+
/// \param Cond Condition of the clause.
282258
/// \param EndLoc Ending location of the clause.
283-
OSSIfClause(OmpSsDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
284-
OmpSsDirectiveKind CaptureRegion, SourceLocation StartLoc,
285-
SourceLocation LParenLoc, SourceLocation NameModifierLoc,
286-
SourceLocation ColonLoc, SourceLocation EndLoc)
287-
: OSSClause(OSSC_if, StartLoc, EndLoc), OSSClauseWithPreInit(this),
288-
LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
289-
NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
290-
setPreInitStmt(HelperCond, CaptureRegion);
291-
}
259+
OSSIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
260+
SourceLocation EndLoc)
261+
: OSSClause(OSSC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
262+
Condition(Cond) {}
292263

293264
/// Build an empty clause.
294265
OSSIfClause()
295-
: OSSClause(OSSC_if, SourceLocation(), SourceLocation()),
296-
OSSClauseWithPreInit(this) {}
266+
: OSSClause(OSSC_if, SourceLocation(), SourceLocation()) {}
297267

298268
/// Sets the location of '('.
299269
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
300270

301271
/// Returns the location of '('.
302272
SourceLocation getLParenLoc() const { return LParenLoc; }
303273

304-
/// Return the location of ':'.
305-
SourceLocation getColonLoc() const { return ColonLoc; }
306-
307274
/// Returns condition.
308275
Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
309276

310-
/// Return directive name modifier associated with the clause.
311-
OmpSsDirectiveKind getNameModifier() const { return NameModifier; }
312-
313-
/// Return the location of directive name modifier.
314-
SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
315-
316277
child_range children() { return child_range(&Condition, &Condition + 1); }
317278

318279
static bool classof(const OSSClause *T) {
@@ -333,7 +294,7 @@ class OSSFinalClause : public OSSClause {
333294
/// Location of '('.
334295
SourceLocation LParenLoc;
335296

336-
/// Condition of the 'if' clause.
297+
/// Condition of the 'final' clause.
337298
Stmt *Condition = nullptr;
338299

339300
/// Set condition.

clang/include/clang/Parse/Parser.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,20 @@ class Parser : public CodeCompletionHandler {
28072807
/// nullptr.
28082808
///
28092809
OSSClause *ParseOmpSsSimpleClause(OmpSsClauseKind Kind, bool ParseOnly);
2810+
2811+
/// Parses clause with a single expression of a kind \a Kind.
2812+
///
2813+
/// \param Kind Kind of current clause.
2814+
/// \param ParseOnly true to skip the clause's semantic actions and return
2815+
/// nullptr.
2816+
///
2817+
OSSClause *ParseOmpSsSingleExprClause(OmpSsClauseKind Kind,
2818+
bool ParseOnly);
28102819
public:
2820+
/// Parses simple expression in parens for single-expression clauses of OmpSs
2821+
/// constructs.
2822+
/// \param RLoc Returned location of right paren.
2823+
ExprResult ParseOmpSsParensExpr(StringRef ClauseName, SourceLocation &RLoc);
28112824

28122825
/// Data used for parsing list of variables in OmpSs clauses.
28132826
struct OmpSsVarListDataTy {
@@ -2819,8 +2832,8 @@ class Parser : public CodeCompletionHandler {
28192832

28202833
/// Parses clauses with list.
28212834
bool ParseOmpSsVarList(OmpSsDirectiveKind DKind, OmpSsClauseKind Kind,
2822-
SmallVectorImpl<Expr *> &Vars,
2823-
OmpSsVarListDataTy &Data);
2835+
SmallVectorImpl<Expr *> &Vars,
2836+
OmpSsVarListDataTy &Data);
28242837
private:
28252838
//===--------------------------------------------------------------------===//
28262839
// OpenMP: Directives and clauses.

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9467,6 +9467,21 @@ class Sema {
94679467
SourceLocation StartLoc, SourceLocation LParenLoc,
94689468
SourceLocation EndLoc);
94699469

9470+
OSSClause *ActOnOmpSsSingleExprClause(OmpSsClauseKind Kind,
9471+
Expr *Expr,
9472+
SourceLocation StartLoc,
9473+
SourceLocation LParenLoc,
9474+
SourceLocation EndLoc);
9475+
9476+
/// Called on well-formed 'if' clause.
9477+
OSSClause *ActOnOmpSsIfClause(Expr *Condition, SourceLocation StartLoc,
9478+
SourceLocation LParenLoc,
9479+
SourceLocation EndLoc);
9480+
/// Called on well-formed 'final' clause.
9481+
OSSClause *ActOnOmpSsFinalClause(Expr *Condition, SourceLocation StartLoc,
9482+
SourceLocation LParenLoc,
9483+
SourceLocation EndLoc);
9484+
94709485
/// The kind of conversion being performed.
94719486
enum CheckedConversionKind {
94729487
/// An implicit conversion.

clang/lib/AST/OmpSsClause.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const OSSClauseWithPreInit *OSSClauseWithPreInit::get(const OSSClause *C) {
5656
return static_cast<const OSSInReductionClause *>(C);
5757
case OSSC_linear:
5858
return static_cast<const OSSLinearClause *>(C);
59-
case OSSC_if:
60-
return static_cast<const OSSIfClause *>(C);
6159
case OSSC_num_threads:
6260
return static_cast<const OSSNumThreadsClause *>(C);
6361
case OSSC_num_teams:

clang/lib/AST/StmtPrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,6 @@ void OSSClausePrinter::VisitOSSClauseList(T *Node, char StartSym) {
664664

665665
void OSSClausePrinter::VisitOSSIfClause(OSSIfClause *Node) {
666666
OS << "if(";
667-
if (Node->getNameModifier() != OSSD_unknown)
668-
OS << getOmpSsDirectiveName(Node->getNameModifier()) << ": ";
669667
Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
670668
OS << ")";
671669
}

clang/lib/Basic/OmpSsKinds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const char *clang::getOmpSsClauseName(OmpSsClauseKind Kind) {
7171
}
7272

7373
unsigned clang::getOmpSsSimpleClauseType(OmpSsClauseKind Kind,
74-
StringRef Str) {
74+
StringRef Str) {
7575
switch (Kind) {
7676
case OSSC_default:
7777
return llvm::StringSwitch<OmpSsDefaultClauseKind>(Str)

clang/lib/CodeGen/CGOmpSsRuntime.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,33 +366,37 @@ void CGOmpSsRuntime::emitTaskCall(CodeGenFunction &CGF,
366366
llvm::Value *ExitCallee = CGM.getIntrinsic(llvm::Intrinsic::directive_region_exit);
367367
SmallVector<llvm::OperandBundleDef, 8> TaskInfo;
368368
TaskInfo.emplace_back("DIR.OSS", llvm::ConstantDataArray::getString(CGM.getLLVMContext(), "TASK"));
369-
for (const Expr *E : Data.SharedVars) {
369+
for (const Expr *E : Data.DSAs.Shareds) {
370370
EmitDSA("QUAL.OSS.SHARED", CGF, E, TaskInfo);
371371
}
372-
for (const Expr *E : Data.PrivateVars) {
372+
for (const Expr *E : Data.DSAs.Privates) {
373373
EmitDSA("QUAL.OSS.PRIVATE", CGF, E, TaskInfo);
374374
}
375-
for (const Expr *E : Data.FirstprivateVars) {
375+
for (const Expr *E : Data.DSAs.Firstprivates) {
376376
EmitDSA("QUAL.OSS.FIRSTPRIVATE", CGF, E, TaskInfo);
377377
}
378-
for (const Expr *E : Data.DependIn) {
378+
for (const Expr *E : Data.Deps.Ins) {
379379
EmitDependency("QUAL.OSS.DEP.IN", CGF, E, TaskInfo);
380380
}
381-
for (const Expr *E : Data.DependOut) {
381+
for (const Expr *E : Data.Deps.Outs) {
382382
EmitDependency("QUAL.OSS.DEP.OUT", CGF, E, TaskInfo);
383383
}
384-
for (const Expr *E : Data.DependInout) {
384+
for (const Expr *E : Data.Deps.Inouts) {
385385
EmitDependency("QUAL.OSS.DEP.INOUT", CGF, E, TaskInfo);
386386
}
387-
for (const Expr *E : Data.DependWeakIn) {
387+
for (const Expr *E : Data.Deps.WeakIns) {
388388
EmitDependency("QUAL.OSS.DEP.WEAKIN", CGF, E, TaskInfo);
389389
}
390-
for (const Expr *E : Data.DependWeakOut) {
390+
for (const Expr *E : Data.Deps.WeakOuts) {
391391
EmitDependency("QUAL.OSS.DEP.WEAKOUT", CGF, E, TaskInfo);
392392
}
393-
for (const Expr *E : Data.DependWeakInout) {
393+
for (const Expr *E : Data.Deps.WeakInouts) {
394394
EmitDependency("QUAL.OSS.DEP.WEAKINOUT", CGF, E, TaskInfo);
395395
}
396+
if (Data.If)
397+
TaskInfo.emplace_back("QUAL.OSS.IF", CGF.EvaluateExprAsBool(Data.If));
398+
if (Data.Final)
399+
TaskInfo.emplace_back("QUAL.OSS.FINAL", CGF.EvaluateExprAsBool(Data.Final));
396400

397401
llvm::Instruction *Result =
398402
CGF.Builder.CreateCall(EntryCallee, {}, llvm::makeArrayRef(TaskInfo));

clang/lib/CodeGen/CGOmpSsRuntime.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,26 @@ class Address;
3232
class CodeGenFunction;
3333
class CodeGenModule;
3434

35+
struct OSSDSADataTy final {
36+
SmallVector<const Expr *, 4> Shareds;
37+
SmallVector<const Expr *, 4> Privates;
38+
SmallVector<const Expr *, 4> Firstprivates;
39+
};
40+
41+
struct OSSDepDataTy final {
42+
SmallVector<const Expr *, 4> WeakIns;
43+
SmallVector<const Expr *, 4> WeakOuts;
44+
SmallVector<const Expr *, 4> WeakInouts;
45+
SmallVector<const Expr *, 4> Ins;
46+
SmallVector<const Expr *, 4> Outs;
47+
SmallVector<const Expr *, 4> Inouts;
48+
};
49+
3550
struct OSSTaskDataTy final {
36-
SmallVector<const Expr *, 4> SharedVars;
37-
SmallVector<const Expr *, 4> PrivateVars;
38-
SmallVector<const Expr *, 4> FirstprivateVars;
39-
SmallVector<const Expr *, 4> DependWeakIn;
40-
SmallVector<const Expr *, 4> DependWeakOut;
41-
SmallVector<const Expr *, 4> DependWeakInout;
42-
SmallVector<const Expr *, 4> DependIn;
43-
SmallVector<const Expr *, 4> DependOut;
44-
SmallVector<const Expr *, 4> DependInout;
51+
OSSDSADataTy DSAs;
52+
OSSDepDataTy Deps;
53+
const Expr *If = nullptr;
54+
const Expr *Final = nullptr;
4555
};
4656

4757
class CGOmpSsRuntime {

clang/lib/CodeGen/CGStmtOmpSs.cpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,66 @@ static void AddDSAData(const OSSTaskDirective &S, SmallVectorImpl<const Expr *>
4141
}
4242
}
4343

44-
void CodeGenFunction::EmitOSSTaskDirective(const OSSTaskDirective &S) {
45-
OSSTaskDataTy Data;
46-
47-
AddDSAData<OSSSharedClause>(S, Data.SharedVars);
48-
AddDSAData<OSSPrivateClause>(S, Data.PrivateVars);
49-
AddDSAData<OSSFirstprivateClause>(S, Data.FirstprivateVars);
44+
static void AddDSAData(const OSSTaskDirective &S, OSSDSADataTy &DSAs) {
45+
AddDSAData<OSSSharedClause>(S, DSAs.Shareds);
46+
AddDSAData<OSSPrivateClause>(S, DSAs.Privates);
47+
AddDSAData<OSSFirstprivateClause>(S, DSAs.Firstprivates);
48+
};
5049

50+
static void AddDepData(const OSSTaskDirective &S, OSSDepDataTy &Deps) {
5151
for (const auto *C : S.getClausesOfKind<OSSDependClause>()) {
5252
ArrayRef<OmpSsDependClauseKind> DepKinds = C->getDependencyKind();
5353
if (DepKinds.size() == 2) {
5454
for (const Expr *Ref : C->varlists()) {
5555
if (DepKinds[0] == OSSC_DEPEND_in
5656
|| DepKinds[1] == OSSC_DEPEND_in)
57-
Data.DependWeakIn.push_back(Ref);
57+
Deps.WeakIns.push_back(Ref);
5858
if (DepKinds[0] == OSSC_DEPEND_out
5959
|| DepKinds[1] == OSSC_DEPEND_out)
60-
Data.DependWeakOut.push_back(Ref);
60+
Deps.WeakOuts.push_back(Ref);
6161
if (DepKinds[0] == OSSC_DEPEND_inout
6262
|| DepKinds[1] == OSSC_DEPEND_inout)
63-
Data.DependWeakInout.push_back(Ref);
63+
Deps.WeakInouts.push_back(Ref);
6464
}
6565
}
6666
else {
6767
for (const Expr *Ref : C->varlists()) {
6868
if (DepKinds[0] == OSSC_DEPEND_in)
69-
Data.DependIn.push_back(Ref);
69+
Deps.Ins.push_back(Ref);
7070
if (DepKinds[0] == OSSC_DEPEND_out)
71-
Data.DependOut.push_back(Ref);
71+
Deps.Outs.push_back(Ref);
7272
if (DepKinds[0] == OSSC_DEPEND_inout)
73-
Data.DependInout.push_back(Ref);
73+
Deps.Inouts.push_back(Ref);
7474
}
7575
}
7676
}
77+
};
78+
79+
static void AddIfData(const OSSTaskDirective &S, const Expr *&IfExpr) {
80+
bool Found = false;
81+
for (const auto *C : S.getClausesOfKind<OSSIfClause>()) {
82+
assert(!Found);
83+
Found = true;
84+
IfExpr = C->getCondition();
85+
}
86+
}
87+
88+
static void AddFinalData(const OSSTaskDirective &S, const Expr * &FinalExpr) {
89+
bool Found = false;
90+
for (const auto *C : S.getClausesOfKind<OSSFinalClause>()) {
91+
assert(!Found);
92+
Found = true;
93+
FinalExpr = C->getCondition();
94+
}
95+
}
96+
97+
void CodeGenFunction::EmitOSSTaskDirective(const OSSTaskDirective &S) {
98+
OSSTaskDataTy Data;
99+
100+
AddDSAData(S, Data.DSAs);
101+
AddDepData(S, Data.Deps);
102+
AddIfData(S, Data.If);
103+
AddFinalData(S, Data.Final);
77104

78105
CGM.getOmpSsRuntime().emitTaskCall(*this, S, S.getBeginLoc(), Data);
79106
}

0 commit comments

Comments
 (0)