Skip to content

Commit 13a1504

Browse files
committed
[OPENMP50]Add initial support for OpenMP 5.0 iterator.
Added basic parsing/semantic analysis/(de)serialization support for iterator expression introduced in OpenMP 5.0.
1 parent af39151 commit 13a1504

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+908
-57
lines changed

clang/include/clang-c/Index.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,12 @@ enum CXCursorKind {
21802180
*/
21812181
CXCursor_OMPArrayShapingExpr = 150,
21822182

2183-
CXCursor_LastExpr = CXCursor_OMPArrayShapingExpr,
2183+
/**
2184+
* OpenMP 5.0 [2.1.6 Iterators]
2185+
*/
2186+
CXCursor_OMPIteratorExpr = 151,
2187+
2188+
CXCursor_LastExpr = CXCursor_OMPIteratorExpr,
21842189

21852190
/* Statements */
21862191
CXCursor_FirstStmt = 200,

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
970970
#include "clang/Basic/OpenCLImageTypes.def"
971971
CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
972972
CanQualType OCLQueueTy, OCLReserveIDTy;
973-
CanQualType OMPArraySectionTy, OMPArrayShapingTy;
973+
CanQualType OMPArraySectionTy, OMPArrayShapingTy, OMPIteratorTy;
974974
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
975975
CanQualType Id##Ty;
976976
#include "clang/Basic/OpenCLExtensionTypes.def"

clang/include/clang/AST/BuiltinTypes.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ PLACEHOLDER_TYPE(OMPArraySection, OMPArraySectionTy)
316316
// A placeholder type for OpenMP array shaping operation.
317317
PLACEHOLDER_TYPE(OMPArrayShaping, OMPArrayShapingTy)
318318

319+
// A placeholder type for OpenMP iterators.
320+
PLACEHOLDER_TYPE(OMPIterator, OMPIteratorTy)
321+
319322
#ifdef LAST_BUILTIN_TYPE
320-
LAST_BUILTIN_TYPE(OMPArrayShaping)
323+
LAST_BUILTIN_TYPE(OMPIterator)
321324
#undef LAST_BUILTIN_TYPE
322325
#endif
323326

clang/include/clang/AST/ComputeDependence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class PseudoObjectExpr;
8888
class AtomicExpr;
8989
class OMPArraySectionExpr;
9090
class OMPArrayShapingExpr;
91+
class OMPIteratorExpr;
9192
class ObjCArrayLiteral;
9293
class ObjCDictionaryLiteral;
9394
class ObjCBoxedExpr;
@@ -174,6 +175,7 @@ ExprDependence computeDependence(AtomicExpr *E);
174175

175176
ExprDependence computeDependence(OMPArraySectionExpr *E);
176177
ExprDependence computeDependence(OMPArrayShapingExpr *E);
178+
ExprDependence computeDependence(OMPIteratorExpr *E);
177179

178180
ExprDependence computeDependence(ObjCArrayLiteral *E);
179181
ExprDependence computeDependence(ObjCDictionaryLiteral *E);

clang/include/clang/AST/ExprOpenMP.h

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,169 @@ class OMPArrayShapingExpr final
205205
return const_child_range(Begin, Begin + NumDims + 1);
206206
}
207207
};
208+
209+
/// OpenMP 5.0 [2.1.6 Iterators]
210+
/// Iterators are identifiers that expand to multiple values in the clause on
211+
/// which they appear.
212+
/// The syntax of the iterator modifier is as follows:
213+
/// \code
214+
/// iterator(iterators-definition)
215+
/// \endcode
216+
/// where iterators-definition is one of the following:
217+
/// \code
218+
/// iterator-specifier [, iterators-definition ]
219+
/// \endcode
220+
/// where iterator-specifier is one of the following:
221+
/// \code
222+
/// [ iterator-type ] identifier = range-specification
223+
/// \endcode
224+
/// where identifier is a base language identifier.
225+
/// iterator-type is a type name.
226+
/// range-specification is of the form begin:end[:step], where begin and end are
227+
/// expressions for which their types can be converted to iterator-type and step
228+
/// is an integral expression.
229+
/// In an iterator-specifier, if the iterator-type is not specified then the
230+
/// type of that iterator is of int type.
231+
/// The iterator-type must be an integral or pointer type.
232+
/// The iterator-type must not be const qualified.
233+
class OMPIteratorExpr final
234+
: public Expr,
235+
private llvm::TrailingObjects<OMPIteratorExpr, Decl *, Expr *,
236+
SourceLocation> {
237+
public:
238+
/// Iterator range representation begin:end[:step].
239+
struct IteratorRange {
240+
Expr *Begin = nullptr;
241+
Expr *End = nullptr;
242+
Expr *Step = nullptr;
243+
};
244+
/// Iterator definition representation.
245+
struct IteratorDefinition {
246+
Decl *IteratorDecl = nullptr;
247+
IteratorRange Range;
248+
SourceLocation AssignmentLoc;
249+
SourceLocation ColonLoc, SecondColonLoc;
250+
};
251+
252+
private:
253+
friend TrailingObjects;
254+
friend class ASTStmtReader;
255+
friend class ASTStmtWriter;
256+
257+
/// Offset in the list of expressions for subelements of the ranges.
258+
enum class RangeExprOffset {
259+
Begin = 0,
260+
End = 1,
261+
Step = 2,
262+
Total = 3,
263+
};
264+
/// Offset in the list of locations for subelements of colon symbols
265+
/// locations.
266+
enum class RangeLocOffset {
267+
AssignLoc = 0,
268+
FirstColonLoc = 1,
269+
SecondColonLoc = 2,
270+
Total = 3,
271+
};
272+
/// Location of 'iterator' keyword.
273+
SourceLocation IteratorKwLoc;
274+
/// Location of '('.
275+
SourceLocation LPLoc;
276+
/// Location of ')'.
277+
SourceLocation RPLoc;
278+
/// Number of iterator definitions.
279+
unsigned NumIterators = 0;
280+
281+
OMPIteratorExpr(QualType ExprTy, SourceLocation IteratorKwLoc,
282+
SourceLocation L, SourceLocation R,
283+
ArrayRef<OMPIteratorExpr::IteratorDefinition> Data);
284+
285+
/// Construct an empty expression.
286+
explicit OMPIteratorExpr(EmptyShell Shell, unsigned NumIterators)
287+
: Expr(OMPIteratorExprClass, Shell), NumIterators(NumIterators) {}
288+
289+
/// Sets basic declaration for the specified iterator definition.
290+
void setIteratorDeclaration(unsigned I, Decl *D);
291+
292+
/// Sets the location of the assignment symbol for the specified iterator
293+
/// definition.
294+
void setAssignmentLoc(unsigned I, SourceLocation Loc);
295+
296+
/// Sets begin, end and optional step expressions for specified iterator
297+
/// definition.
298+
void setIteratorRange(unsigned I, Expr *Begin, SourceLocation ColonLoc,
299+
Expr *End, SourceLocation SecondColonLoc, Expr *Step);
300+
301+
unsigned numTrailingObjects(OverloadToken<Decl *>) const {
302+
return NumIterators;
303+
}
304+
305+
unsigned numTrailingObjects(OverloadToken<Expr *>) const {
306+
return NumIterators * static_cast<int>(RangeExprOffset::Total);
307+
}
308+
309+
public:
310+
static OMPIteratorExpr *Create(const ASTContext &Context, QualType T,
311+
SourceLocation IteratorKwLoc, SourceLocation L,
312+
SourceLocation R,
313+
ArrayRef<IteratorDefinition> Data);
314+
315+
static OMPIteratorExpr *CreateEmpty(const ASTContext &Context,
316+
unsigned NumIterators);
317+
318+
SourceLocation getLParenLoc() const { return LPLoc; }
319+
void setLParenLoc(SourceLocation L) { LPLoc = L; }
320+
321+
SourceLocation getRParenLoc() const { return RPLoc; }
322+
void setRParenLoc(SourceLocation L) { RPLoc = L; }
323+
324+
SourceLocation getIteratorKwLoc() const { return IteratorKwLoc; }
325+
void setIteratorKwLoc(SourceLocation L) { IteratorKwLoc = L; }
326+
SourceLocation getBeginLoc() const LLVM_READONLY { return IteratorKwLoc; }
327+
SourceLocation getEndLoc() const LLVM_READONLY { return RPLoc; }
328+
329+
/// Gets the iterator declaration for the given iterator.
330+
Decl *getIteratorDecl(unsigned I);
331+
const Decl *getIteratorDecl(unsigned I) const {
332+
return const_cast<OMPIteratorExpr *>(this)->getIteratorDecl(I);
333+
}
334+
335+
/// Gets the iterator range for the given iterator.
336+
IteratorRange getIteratorRange(unsigned I);
337+
const IteratorRange getIteratorRange(unsigned I) const {
338+
return const_cast<OMPIteratorExpr *>(this)->getIteratorRange(I);
339+
}
340+
341+
/// Gets the location of '=' for the given iterator definition.
342+
SourceLocation getAssignLoc(unsigned I) const;
343+
/// Gets the location of the first ':' in the range for the given iterator
344+
/// definition.
345+
SourceLocation getColonLoc(unsigned I) const;
346+
/// Gets the location of the second ':' (if any) in the range for the given
347+
/// iteratori definition.
348+
SourceLocation getSecondColonLoc(unsigned I) const;
349+
350+
/// Returns number of iterator definitions.
351+
unsigned numOfIterators() const { return NumIterators; }
352+
353+
static bool classof(const Stmt *T) {
354+
return T->getStmtClass() == OMPIteratorExprClass;
355+
}
356+
357+
// Iterators
358+
child_range children() {
359+
Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
360+
return child_range(
361+
Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
362+
}
363+
const_child_range children() const {
364+
Stmt *const *Begin =
365+
reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
366+
return const_child_range(
367+
Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
368+
}
369+
};
370+
208371
} // end namespace clang
209372

210373
#endif

clang/include/clang/AST/OpenMPClause.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4372,6 +4372,9 @@ class OMPDependClause final
43724372
/// Set colon location.
43734373
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
43744374

4375+
/// Sets optional dependency modifier.
4376+
void setModifier(Expr *DepModifier);
4377+
43754378
public:
43764379
/// Creates clause with a list of variables \a VL.
43774380
///
@@ -4387,7 +4390,7 @@ class OMPDependClause final
43874390
/// clause.
43884391
static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
43894392
SourceLocation LParenLoc,
4390-
SourceLocation EndLoc,
4393+
SourceLocation EndLoc, Expr *DepModifier,
43914394
OpenMPDependClauseKind DepKind,
43924395
SourceLocation DepLoc, SourceLocation ColonLoc,
43934396
ArrayRef<Expr *> VL, unsigned NumLoops);
@@ -4404,6 +4407,12 @@ class OMPDependClause final
44044407
/// Get dependency type.
44054408
OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
44064409

4410+
/// Return optional depend modifier.
4411+
Expr *getModifier();
4412+
const Expr *getModifier() const {
4413+
return const_cast<OMPDependClause *>(this)->getModifier();
4414+
}
4415+
44074416
/// Get dependency type location.
44084417
SourceLocation getDependencyLoc() const { return DepLoc; }
44094418

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,7 @@ DEF_TRAVERSE_STMT(AddrLabelExpr, {})
25522552
DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
25532553
DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
25542554
DEF_TRAVERSE_STMT(OMPArrayShapingExpr, {})
2555+
DEF_TRAVERSE_STMT(OMPIteratorExpr, {})
25552556

25562557
DEF_TRAVERSE_STMT(BlockExpr, {
25572558
TRY_TO(TraverseDecl(S->getBlockDecl()));

clang/include/clang/AST/TextNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class TextNodeDumper
274274
void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
275275
void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
276276
void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
277+
void VisitOMPIteratorExpr(const OMPIteratorExpr *Node);
277278

278279
void VisitRValueReferenceType(const ReferenceType *T);
279280
void VisitArrayType(const ArrayType *T);

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,10 @@ def err_omp_expected_identifier_for_critical : Error<
12201220
"expected identifier specifying the name of the 'omp critical' directive">;
12211221
def err_omp_expected_reduction_identifier : Error<
12221222
"expected identifier or one of the following operators: '+', '-', '*', '&', '|', '^', '&&', or '||'">;
1223+
def err_omp_expected_equal_in_iterator : Error<
1224+
"expected '=' in iterator specifier">;
1225+
def err_omp_expected_punc_after_iterator : Error<
1226+
"expected ',' or ')' after iterator specifier">;
12231227
def err_omp_decl_in_declare_simd_variant : Error<
12241228
"function declaration is expected after 'declare %select{simd|variant}0' directive">;
12251229
def err_omp_unknown_map_type : Error<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9760,6 +9760,14 @@ def note_omp_conversion_here : Note<
97609760
def err_omp_ambiguous_conversion : Error<
97619761
"ambiguous conversion from type %0 to an integral or unscoped "
97629762
"enumeration type">;
9763+
def err_omp_iterator_not_integral_or_pointer : Error<
9764+
"expected integral or pointer type as the iterator-type, not %0">;
9765+
def err_omp_iterator_constant : Error<
9766+
"expected non-constant type as the iterator-type, constant %0 is provided">;
9767+
def err_omp_iterator_step_not_integral : Error<
9768+
"iterator step expression %0 is not the integral expression">;
9769+
def err_omp_iterator_step_constant_zero : Error<
9770+
"iterator step expression %0 evaluates to 0">;
97639771
def err_omp_required_access : Error<
97649772
"%0 variable must be %1">;
97659773
def err_omp_const_variable : Error<
@@ -9953,6 +9961,7 @@ def err_omp_invalid_mapper: Error<
99539961
"cannot find a valid user-defined mapper for type %0 with name %1">;
99549962
def err_omp_array_section_use : Error<"OpenMP array section is not allowed here">;
99559963
def err_omp_array_shaping_use : Error<"OpenMP array shaping operation is not allowed here">;
9964+
def err_omp_iterator_use : Error<"OpenMP iterator is not allowed here">;
99569965
def err_omp_typecheck_section_value : Error<
99579966
"subscripted value is not an array or pointer">;
99589967
def err_omp_typecheck_section_not_integer : Error<
@@ -10031,6 +10040,10 @@ def err_omp_depend_sink_source_not_allowed : Error<
1003110040
"'depend(%select{source|sink:vec}0)' clause%select{|s}0 cannot be mixed with 'depend(%select{sink:vec|source}0)' clause%select{s|}0">;
1003210041
def err_omp_depend_zero_length_array_section_not_allowed : Error<
1003310042
"zero-length array section is not allowed in 'depend' clause">;
10043+
def err_omp_depend_sink_source_with_modifier : Error<
10044+
"depend modifier cannot be used with 'sink' or 'source' depend type">;
10045+
def err_omp_depend_modifier_not_iterator : Error<
10046+
"expected iterator specification as depend modifier">;
1003410047
def err_omp_linear_ordered : Error<
1003510048
"'linear' clause cannot be specified along with 'ordered' clause with a parameter">;
1003610049
def err_omp_unexpected_schedule_modifier : Error<

0 commit comments

Comments
 (0)