Skip to content

Commit 661c090

Browse files
author
Samuel Antao
committedMay 26, 2016
[OpenMP] Parsing and sema support for the to clause
Summary: The patch contains the parsing and sema support for the `to` clause. Patch based on the original post by Kelvin Li. Reviewers: carlo.bertolli, hfinkel, kkwli0, arpith-jacob, ABataev Subscribers: caomhin, cfe-commits Differential Revision: http://reviews.llvm.org/D18597 llvm-svn: 270880
1 parent 7f32420 commit 661c090

25 files changed

+768
-186
lines changed
 

‎clang/include/clang/AST/OpenMPClause.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,6 +4010,109 @@ class OMPDefaultmapClause : public OMPClause {
40104010
return child_range(child_iterator(), child_iterator());
40114011
}
40124012
};
4013+
4014+
/// \brief This represents clause 'to' in the '#pragma omp ...'
4015+
/// directives.
4016+
///
4017+
/// \code
4018+
/// #pragma omp target update to(a,b)
4019+
/// \endcode
4020+
/// In this example directive '#pragma omp target update' has clause 'to'
4021+
/// with the variables 'a' and 'b'.
4022+
///
4023+
class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
4024+
private llvm::TrailingObjects<
4025+
OMPToClause, Expr *, ValueDecl *, unsigned,
4026+
OMPClauseMappableExprCommon::MappableComponent> {
4027+
friend TrailingObjects;
4028+
friend OMPVarListClause;
4029+
friend OMPMappableExprListClause;
4030+
friend class OMPClauseReader;
4031+
4032+
/// Define the sizes of each trailing object array except the last one. This
4033+
/// is required for TrailingObjects to work properly.
4034+
size_t numTrailingObjects(OverloadToken<Expr *>) const {
4035+
return varlist_size();
4036+
}
4037+
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4038+
return getUniqueDeclarationsNum();
4039+
}
4040+
size_t numTrailingObjects(OverloadToken<unsigned>) const {
4041+
return getUniqueDeclarationsNum() + getTotalComponentListNum();
4042+
}
4043+
4044+
/// \brief Build clause with number of variables \a NumVars.
4045+
///
4046+
/// \param StartLoc Starting location of the clause.
4047+
/// \param EndLoc Ending location of the clause.
4048+
/// \param NumVars Number of expressions listed in this clause.
4049+
/// \param NumUniqueDeclarations Number of unique base declarations in this
4050+
/// clause.
4051+
/// \param NumComponentLists Number of component lists in this clause.
4052+
/// \param NumComponents Total number of expression components in the clause.
4053+
///
4054+
explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4055+
SourceLocation EndLoc, unsigned NumVars,
4056+
unsigned NumUniqueDeclarations,
4057+
unsigned NumComponentLists, unsigned NumComponents)
4058+
: OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars,
4059+
NumUniqueDeclarations, NumComponentLists,
4060+
NumComponents) {}
4061+
4062+
/// \brief Build an empty clause.
4063+
///
4064+
/// \param NumVars Number of expressions listed in this clause.
4065+
/// \param NumUniqueDeclarations Number of unique base declarations in this
4066+
/// clause.
4067+
/// \param NumComponentLists Number of component lists in this clause.
4068+
/// \param NumComponents Total number of expression components in the clause.
4069+
///
4070+
explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4071+
unsigned NumComponentLists, unsigned NumComponents)
4072+
: OMPMappableExprListClause(
4073+
OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(),
4074+
NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4075+
4076+
public:
4077+
/// \brief Creates clause with a list of variables \a Vars.
4078+
///
4079+
/// \param C AST context.
4080+
/// \brief StartLoc Starting location of the clause.
4081+
/// \brief EndLoc Ending location of the clause.
4082+
/// \param Vars The original expression used in the clause.
4083+
/// \param Declarations Declarations used in the clause.
4084+
/// \param ComponentLists Component lists used in the clause.
4085+
///
4086+
static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc,
4087+
SourceLocation LParenLoc, SourceLocation EndLoc,
4088+
ArrayRef<Expr *> Vars,
4089+
ArrayRef<ValueDecl *> Declarations,
4090+
MappableExprComponentListsRef ComponentLists);
4091+
4092+
/// \brief Creates an empty clause with the place for \a NumVars variables.
4093+
///
4094+
/// \param C AST context.
4095+
/// \param NumVars Number of expressions listed in the clause.
4096+
/// \param NumUniqueDeclarations Number of unique base declarations in this
4097+
/// clause.
4098+
/// \param NumComponentLists Number of unique base declarations in this
4099+
/// clause.
4100+
/// \param NumComponents Total number of expression components in the clause.
4101+
///
4102+
static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4103+
unsigned NumUniqueDeclarations,
4104+
unsigned NumComponentLists,
4105+
unsigned NumComponents);
4106+
4107+
static bool classof(const OMPClause *T) {
4108+
return T->getClauseKind() == OMPC_to;
4109+
}
4110+
4111+
child_range children() {
4112+
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4113+
reinterpret_cast<Stmt **>(varlist_end()));
4114+
}
4115+
};
40134116
} // end namespace clang
40144117

40154118
#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H

‎clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,12 @@ RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
28842884
return true;
28852885
}
28862886

2887+
template <typename Derived>
2888+
bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
2889+
TRY_TO(VisitOMPClauseList(C));
2890+
return true;
2891+
}
2892+
28872893
// FIXME: look at the following tricky-seeming exprs to see if we
28882894
// need to recurse on anything. These are ones that have methods
28892895
// returning decls or qualtypes or nestednamespecifier -- though I'm

‎clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7934,8 +7934,8 @@ def err_omp_expected_var_name_member_expr_or_array_item : Error<
79347934
"expected variable name%select{|, data member of current class}0, array element or array section">;
79357935
def err_omp_expected_named_var_member_or_array_expression: Error<
79367936
"expected expression containing only member accesses and/or array sections based on named variables">;
7937-
def err_omp_bit_fields_forbidden_in_map_clause : Error<
7938-
"bit fields cannot be used to specify storage in a map clause">;
7937+
def err_omp_bit_fields_forbidden_in_clause : Error<
7938+
"bit fields cannot be used to specify storage in a '%0' clause">;
79397939
def err_array_section_does_not_specify_contiguous_storage : Error<
79407940
"array section does not specify contiguous storage">;
79417941
def err_omp_union_type_not_allowed : Error<
@@ -8076,6 +8076,8 @@ def err_omp_clause_floating_type_arg : Error<
80768076
"arguments of OpenMP clause 'reduction' with bitwise operators cannot be of floating type">;
80778077
def err_omp_once_referenced : Error<
80788078
"variable can appear only once in OpenMP '%0' clause">;
8079+
def err_omp_once_referenced_in_target_update : Error<
8080+
"variable can appear only once in OpenMP 'target update' construct">;
80798081
def note_omp_referenced : Note<
80808082
"previously referenced here">;
80818083
def err_omp_reduction_in_task : Error<
@@ -8213,8 +8215,8 @@ def note_omp_polymorphic_in_target : Note<
82138215
"mappable type cannot be polymorphic">;
82148216
def note_omp_static_member_in_target : Note<
82158217
"mappable type cannot contain static members">;
8216-
def err_omp_threadprivate_in_map : Error<
8217-
"threadprivate variables are not allowed in map clause">;
8218+
def err_omp_threadprivate_in_clause : Error<
8219+
"threadprivate variables are not allowed in '%0' clause">;
82188220
def err_omp_wrong_ordered_loop_count : Error<
82198221
"the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause">;
82208222
def note_collapse_loop_count : Note<

‎clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ OPENMP_CLAUSE(num_tasks, OMPNumTasksClause)
210210
OPENMP_CLAUSE(hint, OMPHintClause)
211211
OPENMP_CLAUSE(dist_schedule, OMPDistScheduleClause)
212212
OPENMP_CLAUSE(defaultmap, OMPDefaultmapClause)
213+
OPENMP_CLAUSE(to, OMPToClause)
213214

214215
// Clauses allowed for OpenMP directive 'parallel'.
215216
OPENMP_PARALLEL_CLAUSE(if)
@@ -450,6 +451,7 @@ OPENMP_TARGET_PARALLEL_FOR_CLAUSE(linear)
450451
// TODO More clauses for 'target update' directive.
451452
OPENMP_TARGET_UPDATE_CLAUSE(if)
452453
OPENMP_TARGET_UPDATE_CLAUSE(device)
454+
OPENMP_TARGET_UPDATE_CLAUSE(to)
453455

454456
// Clauses allowed for OpenMP directive 'teams'.
455457
// TODO More clauses for 'teams' directive.

‎clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8418,6 +8418,11 @@ class Sema {
84188418
OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind,
84198419
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc,
84208420
SourceLocation KindLoc, SourceLocation EndLoc);
8421+
/// \brief Called on well-formed 'to' clause.
8422+
OMPClause *ActOnOpenMPToClause(ArrayRef<Expr *> VarList,
8423+
SourceLocation StartLoc,
8424+
SourceLocation LParenLoc,
8425+
SourceLocation EndLoc);
84218426

84228427
/// \brief The kind of conversion being performed.
84238428
enum CheckedConversionKind {

‎clang/lib/AST/OpenMPClause.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
8787
case OMPC_defaultmap:
8888
case OMPC_unknown:
8989
case OMPC_uniform:
90+
case OMPC_to:
9091
break;
9192
}
9293

@@ -148,6 +149,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
148149
case OMPC_defaultmap:
149150
case OMPC_unknown:
150151
case OMPC_uniform:
152+
case OMPC_to:
151153
break;
152154
}
153155

@@ -625,3 +627,52 @@ OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
625627
return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
626628
NumComponentLists, NumComponents);
627629
}
630+
631+
OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
632+
SourceLocation LParenLoc,
633+
SourceLocation EndLoc, ArrayRef<Expr *> Vars,
634+
ArrayRef<ValueDecl *> Declarations,
635+
MappableExprComponentListsRef ComponentLists) {
636+
unsigned NumVars = Vars.size();
637+
unsigned NumUniqueDeclarations =
638+
getUniqueDeclarationsTotalNumber(Declarations);
639+
unsigned NumComponentLists = ComponentLists.size();
640+
unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
641+
642+
// We need to allocate:
643+
// NumVars x Expr* - we have an original list expression for each clause list
644+
// entry.
645+
// NumUniqueDeclarations x ValueDecl* - unique base declarations associated
646+
// with each component list.
647+
// (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
648+
// number of lists for each unique declaration and the size of each component
649+
// list.
650+
// NumComponents x MappableComponent - the total of all the components in all
651+
// the lists.
652+
void *Mem = C.Allocate(
653+
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
654+
OMPClauseMappableExprCommon::MappableComponent>(
655+
NumVars, NumUniqueDeclarations,
656+
NumUniqueDeclarations + NumComponentLists, NumComponents));
657+
658+
OMPToClause *Clause = new (Mem)
659+
OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
660+
NumComponentLists, NumComponents);
661+
662+
Clause->setVarRefs(Vars);
663+
Clause->setClauseInfo(Declarations, ComponentLists);
664+
return Clause;
665+
}
666+
667+
OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
668+
unsigned NumUniqueDeclarations,
669+
unsigned NumComponentLists,
670+
unsigned NumComponents) {
671+
void *Mem = C.Allocate(
672+
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
673+
OMPClauseMappableExprCommon::MappableComponent>(
674+
NumVars, NumUniqueDeclarations,
675+
NumUniqueDeclarations + NumComponentLists, NumComponents));
676+
return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
677+
NumComponentLists, NumComponents);
678+
}

‎clang/lib/AST/StmtPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,14 @@ void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
912912
}
913913
}
914914

915+
void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
916+
if (!Node->varlist_empty()) {
917+
OS << "to";
918+
VisitOMPClauseList(Node, '(');
919+
OS << ")";
920+
}
921+
}
922+
915923
void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
916924
OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
917925
OMPC_dist_schedule, Node->getDistScheduleKind());

‎clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
491491
void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
492492
Profiler->VisitStmt(C->getHint());
493493
}
494+
void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
495+
VisitOMPClauseList(C);
496+
}
494497
}
495498

496499
void

‎clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
162162
case OMPC_num_tasks:
163163
case OMPC_hint:
164164
case OMPC_uniform:
165+
case OMPC_to:
165166
break;
166167
}
167168
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -297,6 +298,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
297298
case OMPC_num_tasks:
298299
case OMPC_hint:
299300
case OMPC_uniform:
301+
case OMPC_to:
300302
break;
301303
}
302304
llvm_unreachable("Invalid OpenMP simple clause kind");

‎clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,7 @@ static void EmitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
31343134
case OMPC_dist_schedule:
31353135
case OMPC_defaultmap:
31363136
case OMPC_uniform:
3137+
case OMPC_to:
31373138
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
31383139
}
31393140
}

‎clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ bool Parser::ParseOpenMPSimpleVarList(
10431043
/// update-clause | capture-clause | seq_cst-clause | device-clause |
10441044
/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
10451045
/// thread_limit-clause | priority-clause | grainsize-clause |
1046-
/// nogroup-clause | num_tasks-clause | hint-clause
1046+
/// nogroup-clause | num_tasks-clause | hint-clause | to-clause
10471047
///
10481048
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
10491049
OpenMPClauseKind CKind, bool FirstClause) {
@@ -1167,6 +1167,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
11671167
case OMPC_flush:
11681168
case OMPC_depend:
11691169
case OMPC_map:
1170+
case OMPC_to:
11701171
Clause = ParseOpenMPVarListClause(DKind, CKind);
11711172
break;
11721173
case OMPC_unknown:
@@ -1727,6 +1728,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
17271728
/// map-clause:
17281729
/// 'map' '(' [ [ always , ]
17291730
/// to | from | tofrom | alloc | release | delete ':' ] list ')';
1731+
/// to-clause:
1732+
/// 'to' '(' list ')'
17301733
///
17311734
/// For 'linear' clause linear-list may have the following forms:
17321735
/// list

0 commit comments

Comments
 (0)
Please sign in to comment.