diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -107,6 +107,89 @@ static bool classof(const OMPClause *) { return true; } }; +template +struct OMPNoChildClause : public OMPClause { + /// Build '\p ClauseKind' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPNoChildClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(ClauseKind, StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPNoChildClause() + : OMPClause(ClauseKind, SourceLocation(), SourceLocation()) {} + + child_range children() { + return child_range(child_iterator(), child_iterator()); + } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == ClauseKind; + } +}; + +template +class OMPOneStmtClause : public Base { + + /// Location of '('. + SourceLocation LParenLoc; + + /// Sub-expression. + Stmt *S = nullptr; + +protected: + void setStmt(Stmt *S) { this->S = S; } + +public: + OMPOneStmtClause(Stmt *S, SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation EndLoc) + : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {} + + OMPOneStmtClause() : Base(ClauseKind, SourceLocation(), SourceLocation()) {} + + /// Return the associated statement, potentially casted to \p T. + template T *getStmtAs() const { return cast_or_null(S); } + + /// Sets the location of '('. + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + + /// Returns the location of '('. + SourceLocation getLParenLoc() const { return LParenLoc; } + + using child_iterator = StmtIterator; + using const_child_iterator = ConstStmtIterator; + using child_range = llvm::iterator_range; + using const_child_range = llvm::iterator_range; + + child_range children() { return child_range(&S, &S + 1); } + + const_child_range children() const { return const_child_range(&S, &S + 1); } + + // TODO: Consider making the getAddrOfExprAsWritten version the default. + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == ClauseKind; + } +}; + /// Class that handles pre-initialization statement for some clauses, like /// 'shedule', 'firstprivate' etc. class OMPClauseWithPreInit { @@ -267,17 +350,12 @@ /// \endcode /// In this example directive '#pragma omp allocate' has simple 'allocator' /// clause with the allocator 'omp_default_mem_alloc'. -class OMPAllocatorClause : public OMPClause { +class OMPAllocatorClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Expression with the allocator. - Stmt *Allocator = nullptr; - /// Set allocator. - void setAllocator(Expr *A) { Allocator = A; } + void setAllocator(Expr *A) { setStmt(A); } public: /// Build 'allocator' clause with the given allocator. @@ -288,39 +366,13 @@ /// \param EndLoc Ending location of the clause. OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_allocator, StartLoc, EndLoc), - LParenLoc(LParenLoc), Allocator(A) {} + : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - OMPAllocatorClause() - : OMPClause(llvm::omp::OMPC_allocator, SourceLocation(), - SourceLocation()) {} - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPAllocatorClause() : OMPOneStmtClause() {} /// Returns allocator. - Expr *getAllocator() const { return cast_or_null(Allocator); } - - child_range children() { return child_range(&Allocator, &Allocator + 1); } - - const_child_range children() const { - return const_child_range(&Allocator, &Allocator + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_allocator; - } + Expr *getAllocator() const { return getStmtAs(); } }; /// This represents the 'align' clause in the '#pragma omp allocate' @@ -332,20 +384,12 @@ /// In this example directive '#pragma omp allocate' has simple 'allocator' /// clause with the allocator 'omp_default_mem_alloc' and align clause with /// value of 8. -class OMPAlignClause final : public OMPClause { +class OMPAlignClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Alignment specified with align clause. - Stmt *Alignment = nullptr; - /// Set alignment value. - void setAlignment(Expr *A) { Alignment = A; } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + void setAlignment(Expr *A) { setStmt(A); } /// Build 'align' clause with the given alignment /// @@ -355,12 +399,10 @@ /// \param EndLoc Ending location of the clause. OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_align, StartLoc, EndLoc), - LParenLoc(LParenLoc), Alignment(A) {} + : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - OMPAlignClause() - : OMPClause(llvm::omp::OMPC_align, SourceLocation(), SourceLocation()) {} + OMPAlignClause() : OMPOneStmtClause() {} public: /// Build 'align' clause with the given alignment @@ -374,28 +416,8 @@ SourceLocation LParenLoc, SourceLocation EndLoc); - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } - /// Returns alignment - Expr *getAlignment() const { return cast_or_null(Alignment); } - - child_range children() { return child_range(&Alignment, &Alignment + 1); } - - const_child_range children() const { - return const_child_range(&Alignment, &Alignment + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_align; - } + Expr *getAlignment() const { return getStmtAs(); } }; /// This represents clause 'allocate' in the '#pragma omp ...' directives. @@ -603,17 +625,13 @@ /// \endcode /// In this example directive '#pragma omp task' has simple 'final' /// clause with condition 'a > 5'. -class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit { +class OMPFinalClause final + : public OMPOneStmtClause, + public OMPClauseWithPreInit { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Condition of the 'if' clause. - Stmt *Condition = nullptr; - /// Set condition. - void setCondition(Expr *Cond) { Condition = Cond; } + void setCondition(Expr *Cond) { setStmt(Cond); } public: /// Build 'final' clause with condition \a Cond. @@ -628,42 +646,23 @@ OMPFinalClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_final, StartLoc, EndLoc), - OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) { + : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), + OMPClauseWithPreInit(this) { setPreInitStmt(HelperCond, CaptureRegion); } /// Build an empty clause. - OMPFinalClause() - : OMPClause(llvm::omp::OMPC_final, SourceLocation(), SourceLocation()), - OMPClauseWithPreInit(this) {} - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPFinalClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} /// Returns condition. - Expr *getCondition() const { return cast_or_null(Condition); } - - child_range children() { return child_range(&Condition, &Condition + 1); } - - const_child_range children() const { - return const_child_range(&Condition, &Condition + 1); - } + Expr *getCondition() const { return getStmtAs(); } child_range used_children(); const_child_range used_children() const { auto Children = const_cast(this)->used_children(); return const_child_range(Children.begin(), Children.end()); } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_final; - } }; - /// This represents 'num_threads' clause in the '#pragma omp ...' /// directive. /// @@ -672,17 +671,13 @@ /// \endcode /// In this example directive '#pragma omp parallel' has simple 'num_threads' /// clause with number of threads '6'. -class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit { +class OMPNumThreadsClause final + : public OMPOneStmtClause, + public OMPClauseWithPreInit { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Condition of the 'num_threads' clause. - Stmt *NumThreads = nullptr; - /// Set condition. - void setNumThreads(Expr *NThreads) { NumThreads = NThreads; } + void setNumThreads(Expr *NThreads) { setStmt(NThreads); } public: /// Build 'num_threads' clause with condition \a NumThreads. @@ -698,43 +693,16 @@ OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_num_threads, StartLoc, EndLoc), - OMPClauseWithPreInit(this), LParenLoc(LParenLoc), - NumThreads(NumThreads) { + : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc), + OMPClauseWithPreInit(this) { setPreInitStmt(HelperNumThreads, CaptureRegion); } /// Build an empty clause. - OMPNumThreadsClause() - : OMPClause(llvm::omp::OMPC_num_threads, SourceLocation(), - SourceLocation()), - OMPClauseWithPreInit(this) {} - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPNumThreadsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} /// Returns number of threads. - Expr *getNumThreads() const { return cast_or_null(NumThreads); } - - child_range children() { return child_range(&NumThreads, &NumThreads + 1); } - - const_child_range children() const { - return const_child_range(&NumThreads, &NumThreads + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_num_threads; - } + Expr *getNumThreads() const { return getStmtAs(); } }; /// This represents 'safelen' clause in the '#pragma omp ...' @@ -749,17 +717,12 @@ /// concurrently with SIMD instructions can have a greater distance /// in the logical iteration space than its value. The parameter of /// the safelen clause must be a constant positive integer expression. -class OMPSafelenClause : public OMPClause { +class OMPSafelenClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Safe iteration space distance. - Stmt *Safelen = nullptr; - /// Set safelen. - void setSafelen(Expr *Len) { Safelen = Len; } + void setSafelen(Expr *Len) { setStmt(Len); } public: /// Build 'safelen' clause. @@ -769,39 +732,13 @@ /// \param EndLoc Ending location of the clause. OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_safelen, StartLoc, EndLoc), - LParenLoc(LParenLoc), Safelen(Len) {} + : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - explicit OMPSafelenClause() - : OMPClause(llvm::omp::OMPC_safelen, SourceLocation(), SourceLocation()) { - } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + explicit OMPSafelenClause() : OMPOneStmtClause() {} /// Return safe iteration space distance. - Expr *getSafelen() const { return cast_or_null(Safelen); } - - child_range children() { return child_range(&Safelen, &Safelen + 1); } - - const_child_range children() const { - return const_child_range(&Safelen, &Safelen + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_safelen; - } + Expr *getSafelen() const { return getStmtAs(); } }; /// This represents 'simdlen' clause in the '#pragma omp ...' @@ -815,17 +752,12 @@ /// If the 'simdlen' clause is used then it specifies the preferred number of /// iterations to be executed concurrently. The parameter of the 'simdlen' /// clause must be a constant positive integer expression. -class OMPSimdlenClause : public OMPClause { +class OMPSimdlenClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Safe iteration space distance. - Stmt *Simdlen = nullptr; - /// Set simdlen. - void setSimdlen(Expr *Len) { Simdlen = Len; } + void setSimdlen(Expr *Len) { setStmt(Len); } public: /// Build 'simdlen' clause. @@ -835,39 +767,13 @@ /// \param EndLoc Ending location of the clause. OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_simdlen, StartLoc, EndLoc), - LParenLoc(LParenLoc), Simdlen(Len) {} + : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - explicit OMPSimdlenClause() - : OMPClause(llvm::omp::OMPC_simdlen, SourceLocation(), SourceLocation()) { - } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + explicit OMPSimdlenClause() : OMPOneStmtClause() {} /// Return safe iteration space distance. - Expr *getSimdlen() const { return cast_or_null(Simdlen); } - - child_range children() { return child_range(&Simdlen, &Simdlen + 1); } - - const_child_range children() const { - return const_child_range(&Simdlen, &Simdlen + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_simdlen; - } + Expr *getSimdlen() const { return getStmtAs(); } }; /// This represents the 'sizes' clause in the '#pragma omp tile' directive. @@ -970,11 +876,11 @@ /// #pragma omp unroll full /// for (int i = 0; i < 64; ++i) /// \endcode -class OMPFullClause final : public OMPClause { +class OMPFullClause final : public OMPNoChildClause { friend class OMPClauseReader; /// Build an empty clause. - explicit OMPFullClause() : OMPClause(llvm::omp::OMPC_full, {}, {}) {} + explicit OMPFullClause() : OMPNoChildClause() {} public: /// Build an AST node for a 'full' clause. @@ -989,22 +895,6 @@ /// /// \param C Context of the AST. static OMPFullClause *CreateEmpty(const ASTContext &C); - - child_range children() { return {child_iterator(), child_iterator()}; } - const_child_range children() const { - return {const_child_iterator(), const_child_iterator()}; - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_full; - } }; /// Representation of the 'partial' clause of the '#pragma omp unroll' @@ -1083,17 +973,12 @@ /// The parameter must be a constant positive integer expression, it specifies /// the number of nested loops that should be collapsed into a single iteration /// space. -class OMPCollapseClause : public OMPClause { +class OMPCollapseClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Number of for-loops. - Stmt *NumForLoops = nullptr; - /// Set the number of associated for-loops. - void setNumForLoops(Expr *Num) { NumForLoops = Num; } + void setNumForLoops(Expr *Num) { setStmt(Num); } public: /// Build 'collapse' clause. @@ -1104,39 +989,13 @@ /// \param EndLoc Ending location of the clause. OMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc), - LParenLoc(LParenLoc), NumForLoops(Num) {} + : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - explicit OMPCollapseClause() - : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(), - SourceLocation()) {} - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + explicit OMPCollapseClause() : OMPOneStmtClause() {} /// Return the number of associated for-loops. - Expr *getNumForLoops() const { return cast_or_null(NumForLoops); } - - child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } - - const_child_range children() const { - return const_child_range(&NumForLoops, &NumForLoops + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_collapse; - } + Expr *getNumForLoops() const { return getStmtAs(); } }; /// This represents 'default' clause in the '#pragma omp ...' directive. @@ -1309,7 +1168,8 @@ /// \endcode /// In this example directive '#pragma omp requires' has 'unified_address' /// clause. -class OMPUnifiedAddressClause final : public OMPClause { +class OMPUnifiedAddressClause final + : public OMPNoChildClause { public: friend class OMPClauseReader; /// Build 'unified_address' clause. @@ -1317,31 +1177,10 @@ /// \param StartLoc Starting location of the clause. /// \param EndLoc Ending location of the clause. OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {} + : OMPNoChildClause(StartLoc, EndLoc) {} /// Build an empty clause. - OMPUnifiedAddressClause() - : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(), - SourceLocation()) {} - - child_range children() { - return child_range(child_iterator(), child_iterator()); - } - - const_child_range children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_unified_address; - } + OMPUnifiedAddressClause() : OMPNoChildClause() {} }; /// This represents 'unified_shared_memory' clause in the '#pragma omp requires' @@ -2083,37 +1922,15 @@ /// #pragma omp for nowait /// \endcode /// In this example directive '#pragma omp for' has 'nowait' clause. -class OMPNowaitClause : public OMPClause { +class OMPNowaitClause final : public OMPNoChildClause { public: /// Build 'nowait' clause. /// /// \param StartLoc Starting location of the clause. /// \param EndLoc Ending location of the clause. - OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {} - - /// Build an empty clause. - OMPNowaitClause() - : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {} - - child_range children() { - return child_range(child_iterator(), child_iterator()); - } - - const_child_range children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_nowait; - } + OMPNowaitClause(SourceLocation StartLoc = SourceLocation(), + SourceLocation EndLoc = SourceLocation()) + : OMPNoChildClause(StartLoc, EndLoc) {} }; /// This represents 'untied' clause in the '#pragma omp ...' directive. @@ -5212,38 +5029,18 @@ /// #pragma omp ordered threads /// \endcode /// In this example directive '#pragma omp ordered' has simple 'threads' clause. -class OMPThreadsClause : public OMPClause { +class OMPThreadsClause final + : public OMPNoChildClause { public: /// Build 'threads' clause. /// /// \param StartLoc Starting location of the clause. /// \param EndLoc Ending location of the clause. OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_threads, StartLoc, EndLoc) {} + : OMPNoChildClause(StartLoc, EndLoc) {} /// Build an empty clause. - OMPThreadsClause() - : OMPClause(llvm::omp::OMPC_threads, SourceLocation(), SourceLocation()) { - } - - child_range children() { - return child_range(child_iterator(), child_iterator()); - } - - const_child_range children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_threads; - } + OMPThreadsClause() : OMPNoChildClause() {} }; /// This represents 'simd' clause in the '#pragma omp ...' directive. @@ -8291,21 +8088,13 @@ /// \endcode /// In this example directive '#pragma omp dispatch' has simple 'novariants' /// clause with condition 'a > 5'. -class OMPNovariantsClause final : public OMPClause, - public OMPClauseWithPreInit { +class OMPNovariantsClause final + : public OMPOneStmtClause, + public OMPClauseWithPreInit { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Condition of the 'if' clause. - Stmt *Condition = nullptr; - /// Set condition. - void setCondition(Expr *Cond) { Condition = Cond; } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + void setCondition(Expr *Cond) { setStmt(Cond); } public: /// Build 'novariants' clause with condition \a Cond. @@ -8321,38 +8110,22 @@ OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_novariants, StartLoc, EndLoc), - OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) { + : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), + OMPClauseWithPreInit(this) { setPreInitStmt(HelperCond, CaptureRegion); } /// Build an empty clause. - OMPNovariantsClause() - : OMPClause(llvm::omp::OMPC_novariants, SourceLocation(), - SourceLocation()), - OMPClauseWithPreInit(this) {} - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPNovariantsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} /// Returns condition. - Expr *getCondition() const { return cast_or_null(Condition); } - - child_range children() { return child_range(&Condition, &Condition + 1); } - - const_child_range children() const { - return const_child_range(&Condition, &Condition + 1); - } + Expr *getCondition() const { return getStmtAs(); } child_range used_children(); const_child_range used_children() const { auto Children = const_cast(this)->used_children(); return const_child_range(Children.begin(), Children.end()); } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_novariants; - } }; /// This represents 'nocontext' clause in the '#pragma omp ...' directive. @@ -8362,20 +8135,13 @@ /// \endcode /// In this example directive '#pragma omp dispatch' has simple 'nocontext' /// clause with condition 'a > 5'. -class OMPNocontextClause final : public OMPClause, public OMPClauseWithPreInit { +class OMPNocontextClause final + : public OMPOneStmtClause, + public OMPClauseWithPreInit { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Condition of the 'if' clause. - Stmt *Condition = nullptr; - /// Set condition. - void setCondition(Expr *Cond) { Condition = Cond; } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + void setCondition(Expr *Cond) { setStmt(Cond); } public: /// Build 'nocontext' clause with condition \a Cond. @@ -8390,38 +8156,22 @@ OMPNocontextClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_nocontext, StartLoc, EndLoc), - OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) { + : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), + OMPClauseWithPreInit(this) { setPreInitStmt(HelperCond, CaptureRegion); } /// Build an empty clause. - OMPNocontextClause() - : OMPClause(llvm::omp::OMPC_nocontext, SourceLocation(), - SourceLocation()), - OMPClauseWithPreInit(this) {} - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPNocontextClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} /// Returns condition. - Expr *getCondition() const { return cast_or_null(Condition); } - - child_range children() { return child_range(&Condition, &Condition + 1); } - - const_child_range children() const { - return const_child_range(&Condition, &Condition + 1); - } + Expr *getCondition() const { return getStmtAs(); } child_range used_children(); const_child_range used_children() const { auto Children = const_cast(this)->used_children(); return const_child_range(Children.begin(), Children.end()); } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_nocontext; - } }; /// This represents 'detach' clause in the '#pragma omp task' directive. @@ -8431,20 +8181,12 @@ /// \endcode /// In this example directive '#pragma omp detach' has simple 'detach' clause /// with the variable 'evt'. -class OMPDetachClause final : public OMPClause { +class OMPDetachClause final + : public OMPOneStmtClause { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Expression of the 'detach' clause. - Stmt *Evt = nullptr; - /// Set condition. - void setEventHandler(Expr *E) { Evt = E; } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + void setEventHandler(Expr *E) { setStmt(E); } public: /// Build 'detach' clause with event-handler \a Evt. @@ -8455,35 +8197,13 @@ /// \param EndLoc Ending location of the clause. OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_detach, StartLoc, EndLoc), - LParenLoc(LParenLoc), Evt(Evt) {} + : OMPOneStmtClause(Evt, StartLoc, LParenLoc, EndLoc) {} /// Build an empty clause. - OMPDetachClause() - : OMPClause(llvm::omp::OMPC_detach, SourceLocation(), SourceLocation()) {} - - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPDetachClause() : OMPOneStmtClause() {} /// Returns event-handler expression. - Expr *getEventHandler() const { return cast_or_null(Evt); } - - child_range children() { return child_range(&Evt, &Evt + 1); } - - const_child_range children() const { - return const_child_range(&Evt, &Evt + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_detach; - } + Expr *getEventHandler() const { return getStmtAs(); } }; /// This represents clause 'inclusive' in the '#pragma omp scan' directive. @@ -8867,20 +8587,13 @@ /// \endcode /// In this example directive '#pragma omp masked' has 'filter' clause with /// thread id. -class OMPFilterClause final : public OMPClause, public OMPClauseWithPreInit { +class OMPFilterClause final + : public OMPOneStmtClause, + public OMPClauseWithPreInit { friend class OMPClauseReader; - /// Location of '('. - SourceLocation LParenLoc; - - /// Express of the 'filter' clause. - Stmt *ThreadID = nullptr; - /// Sets the thread identifier. - void setThreadID(Expr *TID) { ThreadID = TID; } - - /// Sets the location of '('. - void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + void setThreadID(Expr *TID) { setStmt(TID); } public: /// Build 'filter' clause with thread-id \a ThreadID. @@ -8895,40 +8608,19 @@ OMPFilterClause(Expr *ThreadID, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_filter, StartLoc, EndLoc), - OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadID(ThreadID) { + : OMPOneStmtClause(ThreadID, StartLoc, LParenLoc, EndLoc), + OMPClauseWithPreInit(this) { setPreInitStmt(HelperE, CaptureRegion); } /// Build an empty clause. - OMPFilterClause() - : OMPClause(llvm::omp::OMPC_filter, SourceLocation(), SourceLocation()), - OMPClauseWithPreInit(this) {} - /// Returns the location of '('. - SourceLocation getLParenLoc() const { return LParenLoc; } + OMPFilterClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} /// Return thread identifier. - Expr *getThreadID() { return cast(ThreadID); } + Expr *getThreadID() const { return getStmtAs(); } /// Return thread identifier. - Expr *getThreadID() const { return cast(ThreadID); } - - child_range children() { return child_range(&ThreadID, &ThreadID + 1); } - - const_child_range children() const { - return const_child_range(&ThreadID, &ThreadID + 1); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_filter; - } + Expr *getThreadID() { return getStmtAs(); } }; /// This represents 'bind' clause in the '#pragma omp ...' directives. @@ -8936,7 +8628,7 @@ /// \code /// #pragma omp loop bind(parallel) /// \endcode -class OMPBindClause final : public OMPClause { +class OMPBindClause final : public OMPNoChildClause { friend class OMPClauseReader; /// Location of '('. @@ -8967,12 +8659,11 @@ OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) - : OMPClause(llvm::omp::OMPC_bind, StartLoc, EndLoc), LParenLoc(LParenLoc), - Kind(K), KindLoc(KLoc) {} + : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Kind(K), + KindLoc(KLoc) {} /// Build an empty clause. - OMPBindClause() - : OMPClause(llvm::omp::OMPC_bind, SourceLocation(), SourceLocation()) {} + OMPBindClause() : OMPNoChildClause() {} public: /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread'). @@ -9000,25 +8691,6 @@ /// Returns location of clause kind. SourceLocation getBindKindLoc() const { return KindLoc; } - - child_range children() { - return child_range(child_iterator(), child_iterator()); - } - - const_child_range children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - child_range used_children() { - return child_range(child_iterator(), child_iterator()); - } - const_child_range used_children() const { - return const_child_range(const_child_iterator(), const_child_iterator()); - } - - static bool classof(const OMPClause *T) { - return T->getClauseKind() == llvm::omp::OMPC_bind; - } }; /// This class implements a simple visitor for OMPClause diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -313,7 +313,7 @@ OMPClause::child_range OMPFinalClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPClause::child_range OMPPriorityClause::used_children() { @@ -325,13 +325,13 @@ OMPClause::child_range OMPNovariantsClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPClause::child_range OMPNocontextClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,