diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -20,6 +20,9 @@ #include "clang/AST/StmtCXX.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/Support/TrailingObjects.h" namespace clang { @@ -27,35 +30,170 @@ // AST classes for directives. //===----------------------------------------------------------------------===// +/// Contains data for OpenMP executable directives: clauses, children +/// expressions/statements (helpers for codegen) and associated statement, if +/// any. +class OMPChildren final + : private llvm::TrailingObjects { + friend class OMPClauseReader; + friend class TrailingObjects; + /// Numbers of clauses. + unsigned NumClauses = 0; + /// Number of child expressions/stmts. + unsigned NumChildren = 0; + /// true if the directive has associated statement. + bool HasAssociatedStmt = false; + + /// Define the sizes of each trailing object array except the last one. This + /// is required for TrailingObjects to work properly. + size_t numTrailingObjects(OverloadToken) const { + return NumClauses; + } + + OMPChildren() = delete; + + OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt) + : NumClauses(NumClauses), NumChildren(NumChildren), + HasAssociatedStmt(HasAssociatedStmt) {} + +public: + static OMPChildren *Create(const ASTContext &C, + ArrayRef Clauses); + static OMPChildren *Create(const ASTContext &C, ArrayRef Clauses, + Stmt *S, unsigned NumChildren = 0); + static OMPChildren *CreateEmpty(const ASTContext &C, unsigned NumClauses, + bool HasAssociatedStmt = false, + unsigned NumChildren = 0); + + unsigned getNumClauses() const { return NumClauses; } + unsigned getNumChildren() const { return NumChildren; } + bool hasAssociatedStmt() const { return HasAssociatedStmt; } + + /// Set associated statement. + void setAssociatedStmt(Stmt *S) { + getTrailingObjects()[NumChildren] = S; + } + + void setChildren(ArrayRef Children); + + /// Sets the list of variables for this clause. + /// + /// \param Clauses The list of clauses for the directive. + /// + void setClauses(ArrayRef Clauses); + + /// Returns statement associated with the directive. + const Stmt *getAssociatedStmt() const { + return const_cast(this)->getAssociatedStmt(); + } + Stmt *getAssociatedStmt() { + assert(HasAssociatedStmt && + "Expected directive with the associated statement."); + return getTrailingObjects()[NumChildren]; + } + + /// Get the clauses storage. + MutableArrayRef getClauses() { + return llvm::makeMutableArrayRef(getTrailingObjects(), + NumClauses); + } + ArrayRef getClauses() const { + return const_cast(this)->getClauses(); + } + + /// Returns the captured statement associated with the + /// component region within the (combined) directive. + /// + /// \param RegionKind Component region kind. + const CapturedStmt * + getCapturedStmt(OpenMPDirectiveKind RegionKind, + ArrayRef CaptureRegions) const { + assert(llvm::any_of( + CaptureRegions, + [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) && + "RegionKind not found in OpenMP CaptureRegions."); + auto *CS = cast(getAssociatedStmt()); + for (auto ThisCaptureRegion : CaptureRegions) { + if (ThisCaptureRegion == RegionKind) + return CS; + CS = cast(CS->getCapturedStmt()); + } + llvm_unreachable("Incorrect RegionKind specified for directive."); + } + + /// Get innermost captured statement for the construct. + CapturedStmt * + getInnermostCapturedStmt(ArrayRef CaptureRegions) { + assert(hasAssociatedStmt() && "Must have associated captured statement."); + assert(!CaptureRegions.empty() && + "At least one captured statement must be provided."); + auto *CS = cast(getAssociatedStmt()); + for (unsigned Level = CaptureRegions.size(); Level > 1; --Level) + CS = cast(CS->getCapturedStmt()); + return CS; + } + + const CapturedStmt * + getInnermostCapturedStmt(ArrayRef CaptureRegions) const { + return const_cast(this)->getInnermostCapturedStmt( + CaptureRegions); + } + + MutableArrayRef getChildren(); + ArrayRef getChildren() const { + return const_cast(this)->getChildren(); + } + + Stmt *getRawStmt() { + assert(HasAssociatedStmt && + "Expected directive with the associated statement."); + if (auto *CS = dyn_cast(getAssociatedStmt())) { + Stmt *S = nullptr; + do { + S = CS->getCapturedStmt(); + CS = dyn_cast(S); + } while (CS); + return S; + } + return getAssociatedStmt(); + } + const Stmt *getRawStmt() const { + return const_cast(this)->getRawStmt(); + } + + Stmt::child_range getAssociatedStmtAsRange() { + if (!HasAssociatedStmt) + return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator()); + return Stmt::child_range(&getTrailingObjects()[NumChildren], + &getTrailingObjects()[NumChildren + 1]); + } +}; + /// This is a basic class for representing single OpenMP executable /// directive. /// class OMPExecutableDirective : public Stmt { friend class ASTStmtReader; + friend class ASTStmtWriter; + /// Kind of the directive. - OpenMPDirectiveKind Kind; + OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown; /// Starting location of the directive (directive keyword). SourceLocation StartLoc; /// Ending location of the directive. SourceLocation EndLoc; - /// Numbers of clauses. - const unsigned NumClauses; - /// Number of child expressions/stmts. - const unsigned NumChildren; - /// Offset from this to the start of clauses. - /// There are NumClauses pointers to clauses, they are followed by - /// NumChildren pointers to child stmts/exprs (if the directive type - /// requires an associated stmt, then it has to be the first of them). - const unsigned ClausesOffset; /// Get the clauses storage. MutableArrayRef getClauses() { - OMPClause **ClauseStorage = reinterpret_cast( - reinterpret_cast(this) + ClausesOffset); - return MutableArrayRef(ClauseStorage, NumClauses); + if (!Data) + return llvm::None; + return Data->getClauses(); } protected: + /// Data, associated with the directive. + OMPChildren *Data = nullptr; + /// Build instance of directive of class \a K. /// /// \param SC Statement class. @@ -66,25 +204,34 @@ template OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses, unsigned NumChildren) + OMPChildren *Data = nullptr) : Stmt(SC), Kind(K), StartLoc(std::move(StartLoc)), - EndLoc(std::move(EndLoc)), NumClauses(NumClauses), - NumChildren(NumChildren), - ClausesOffset(llvm::alignTo(sizeof(T), alignof(OMPClause *))) {} + EndLoc(std::move(EndLoc)), Data(Data) {} - /// Sets the list of variables for this clause. - /// - /// \param Clauses The list of clauses for the directive. - /// - void setClauses(ArrayRef Clauses); + template + static T *createDirective(const ASTContext &C, ArrayRef Clauses, + Stmt *AssociatedStmt, unsigned NumChildren, + Params &&... P) { + auto *Data = OMPChildren::Create(C, Clauses, AssociatedStmt, NumChildren); + return new (C) T(std::forward(P)..., Data); + } - /// Set the associated statement for the directive. - /// - /// /param S Associated statement. - /// - void setAssociatedStmt(Stmt *S) { - assert(hasAssociatedStmt() && "no associated statement."); - *child_begin() = S; + template + static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses, + bool HasAssociatedStmt, unsigned NumChildren, + Params &&... P) { + auto *Data = + OMPChildren::CreateEmpty(C, NumClauses, HasAssociatedStmt, NumChildren); + return new (C) T(std::forward(P)..., Data); + } + + template + static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses, + bool HasAssociatedStmt = false, + unsigned NumChildren = 0) { + auto *Data = + OMPChildren::CreateEmpty(C, NumClauses, HasAssociatedStmt, NumChildren); + return new (C) T(Data); } public: @@ -238,7 +385,11 @@ void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } /// Get number of clauses. - unsigned getNumClauses() const { return NumClauses; } + unsigned getNumClauses() const { + if (!Data) + return 0; + return Data->getNumClauses(); + } /// Returns specified clause. /// @@ -247,50 +398,37 @@ OMPClause *getClause(unsigned i) const { return clauses()[i]; } /// Returns true if directive has associated statement. - bool hasAssociatedStmt() const { return NumChildren > 0; } + bool hasAssociatedStmt() const { return Data && Data->hasAssociatedStmt(); } /// Returns statement associated with the directive. const Stmt *getAssociatedStmt() const { - assert(hasAssociatedStmt() && "no associated statement."); - return *child_begin(); + return const_cast(this)->getAssociatedStmt(); } Stmt *getAssociatedStmt() { - assert(hasAssociatedStmt() && "no associated statement."); - return *child_begin(); + assert(hasAssociatedStmt() && + "Expected directive with the associated statement."); + return Data->getAssociatedStmt(); } /// Returns the captured statement associated with the /// component region within the (combined) directive. - // - // \param RegionKind Component region kind. + /// + /// \param RegionKind Component region kind. const CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const { + assert(hasAssociatedStmt() && + "Expected directive with the associated statement."); SmallVector CaptureRegions; getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind()); - assert(std::any_of( - CaptureRegions.begin(), CaptureRegions.end(), - [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) && - "RegionKind not found in OpenMP CaptureRegions."); - auto *CS = cast(getAssociatedStmt()); - for (auto ThisCaptureRegion : CaptureRegions) { - if (ThisCaptureRegion == RegionKind) - return CS; - CS = cast(CS->getCapturedStmt()); - } - llvm_unreachable("Incorrect RegionKind specified for directive."); + return Data->getCapturedStmt(RegionKind, CaptureRegions); } /// Get innermost captured statement for the construct. CapturedStmt *getInnermostCapturedStmt() { - assert(hasAssociatedStmt() && getAssociatedStmt() && - "Must have associated statement."); + assert(hasAssociatedStmt() && + "Expected directive with the associated statement."); SmallVector CaptureRegions; getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind()); - assert(!CaptureRegions.empty() && - "At least one captured statement must be provided."); - auto *CS = cast(getAssociatedStmt()); - for (unsigned Level = CaptureRegions.size(); Level > 1; --Level) - CS = cast(CS->getCapturedStmt()); - return CS; + return Data->getInnermostCapturedStmt(CaptureRegions); } const CapturedStmt *getInnermostCapturedStmt() const { @@ -306,26 +444,19 @@ } child_range children() { - if (!hasAssociatedStmt()) + if (!Data) return child_range(child_iterator(), child_iterator()); - Stmt **ChildStorage = reinterpret_cast(getClauses().end()); - /// Do not mark all the special expression/statements as children, except - /// for the associated statement. - return child_range(ChildStorage, ChildStorage + 1); + return Data->getAssociatedStmtAsRange(); } const_child_range children() const { - if (!hasAssociatedStmt()) - return const_child_range(const_child_iterator(), const_child_iterator()); - Stmt **ChildStorage = reinterpret_cast( - const_cast(this)->getClauses().end()); - return const_child_range(ChildStorage, ChildStorage + 1); + return const_cast(this)->children(); } - ArrayRef clauses() { return getClauses(); } - ArrayRef clauses() const { - return const_cast(this)->getClauses(); + if (!Data) + return llvm::None; + return Data->getClauses(); } /// Returns whether or not this is a Standalone directive. @@ -337,11 +468,18 @@ /// Returns the AST node representing OpenMP structured-block of this /// OpenMP executable directive, /// Prerequisite: Executable Directive must not be Standalone directive. - const Stmt *getStructuredBlock() const; + const Stmt *getStructuredBlock() const { + return const_cast(this)->getStructuredBlock(); + } + Stmt *getStructuredBlock(); - Stmt *getStructuredBlock() { - return const_cast( - const_cast(this)->getStructuredBlock()); + const Stmt *getRawStmt() const { + return const_cast(this)->getRawStmt(); + } + Stmt *getRawStmt() { + assert(hasAssociatedStmt() && + "Expected directive with the associated statement."); + return Data->getRawStmt(); } }; @@ -356,36 +494,34 @@ /// class OMPParallelDirective : public OMPExecutableDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending Location of the directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelDirectiveClass, llvm::omp::OMPD_parallel, StartLoc, EndLoc, - NumClauses, 1), - HasCancel(false) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPParallelDirective(unsigned NumClauses) + explicit OMPParallelDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelDirectiveClass, llvm::omp::OMPD_parallel, SourceLocation(), - SourceLocation(), NumClauses, 1), - HasCancel(false) {} + SourceLocation(), Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -416,8 +552,12 @@ unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[0]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this)->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -433,7 +573,7 @@ class OMPLoopDirective : public OMPExecutableDirective { friend class ASTStmtReader; /// Number of collapsed loops as specified by 'collapse' clause. - unsigned CollapsedNum; + unsigned CollapsedNum = 0; /// Offsets to the stored exprs. /// This enumeration contains offsets to all the pointers to children @@ -452,110 +592,110 @@ /// (e.g. 'distribute parallel for') /// enum { - AssociatedStmtOffset = 0, - IterationVariableOffset = 1, - LastIterationOffset = 2, - CalcLastIterationOffset = 3, - PreConditionOffset = 4, - CondOffset = 5, - InitOffset = 6, - IncOffset = 7, - PreInitsOffset = 8, + IterationVariableOffset = 0, + LastIterationOffset = 1, + CalcLastIterationOffset = 2, + PreConditionOffset = 3, + CondOffset = 4, + InitOffset = 5, + IncOffset = 6, + PreInitsOffset = 7, // The '...End' enumerators do not correspond to child expressions - they // specify the offset to the end (and start of the following counters/ // updates/finals/dependent_counters/dependent_inits/finals_conditions // arrays). - DefaultEnd = 9, + DefaultEnd = 8, // The following 8 exprs are used by worksharing and distribute loops only. - IsLastIterVariableOffset = 9, - LowerBoundVariableOffset = 10, - UpperBoundVariableOffset = 11, - StrideVariableOffset = 12, - EnsureUpperBoundOffset = 13, - NextLowerBoundOffset = 14, - NextUpperBoundOffset = 15, - NumIterationsOffset = 16, + IsLastIterVariableOffset = 8, + LowerBoundVariableOffset = 9, + UpperBoundVariableOffset = 10, + StrideVariableOffset = 11, + EnsureUpperBoundOffset = 12, + NextLowerBoundOffset = 13, + NextUpperBoundOffset = 14, + NumIterationsOffset = 15, // Offset to the end for worksharing loop directives. - WorksharingEnd = 17, - PrevLowerBoundVariableOffset = 17, - PrevUpperBoundVariableOffset = 18, - DistIncOffset = 19, - PrevEnsureUpperBoundOffset = 20, - CombinedLowerBoundVariableOffset = 21, - CombinedUpperBoundVariableOffset = 22, - CombinedEnsureUpperBoundOffset = 23, - CombinedInitOffset = 24, - CombinedConditionOffset = 25, - CombinedNextLowerBoundOffset = 26, - CombinedNextUpperBoundOffset = 27, - CombinedDistConditionOffset = 28, - CombinedParForInDistConditionOffset = 29, + WorksharingEnd = 16, + PrevLowerBoundVariableOffset = 16, + PrevUpperBoundVariableOffset = 17, + DistIncOffset = 18, + PrevEnsureUpperBoundOffset = 19, + CombinedLowerBoundVariableOffset = 20, + CombinedUpperBoundVariableOffset = 21, + CombinedEnsureUpperBoundOffset = 22, + CombinedInitOffset = 23, + CombinedConditionOffset = 24, + CombinedNextLowerBoundOffset = 25, + CombinedNextUpperBoundOffset = 26, + CombinedDistConditionOffset = 27, + CombinedParForInDistConditionOffset = 28, // Offset to the end (and start of the following // counters/updates/finals/dependent_counters/dependent_inits/finals_conditions // arrays) for combined distribute loop directives. - CombinedDistributeEnd = 30, + CombinedDistributeEnd = 29, }; /// Get the counters storage. MutableArrayRef getCounters() { - Expr **Storage = reinterpret_cast( - &(*(std::next(child_begin(), getArraysOffset(getDirectiveKind()))))); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind())]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the private counters storage. MutableArrayRef getPrivateCounters() { - Expr **Storage = reinterpret_cast(&*std::next( - child_begin(), getArraysOffset(getDirectiveKind()) + CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the updates storage. MutableArrayRef getInits() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 2 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 2 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the updates storage. MutableArrayRef getUpdates() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 3 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 3 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the final counter updates storage. MutableArrayRef getFinals() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 4 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 4 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the dependent counters storage. MutableArrayRef getDependentCounters() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 5 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 5 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the dependent inits storage. MutableArrayRef getDependentInits() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 6 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 6 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } /// Get the finals conditions storage. MutableArrayRef getFinalsConditions() { - Expr **Storage = reinterpret_cast( - &*std::next(child_begin(), - getArraysOffset(getDirectiveKind()) + 7 * CollapsedNum)); - return MutableArrayRef(Storage, CollapsedNum); + auto **Storage = reinterpret_cast( + &Data->getChildren()[getArraysOffset(getDirectiveKind()) + + 7 * CollapsedNum]); + return llvm::makeMutableArrayRef(Storage, CollapsedNum); } protected: @@ -566,17 +706,14 @@ /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed loops from 'collapse' clause. - /// \param NumClauses Number of clauses. - /// \param NumSpecialChildren Number of additional directive-specific stmts. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// template OMPLoopDirective(const T *That, StmtClass SC, OpenMPDirectiveKind Kind, SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses, - unsigned NumSpecialChildren = 0) - : OMPExecutableDirective(That, SC, Kind, StartLoc, EndLoc, NumClauses, - numLoopChildren(CollapsedNum, Kind) + - NumSpecialChildren), + unsigned CollapsedNum, OMPChildren *Data) + : OMPExecutableDirective(That, SC, Kind, StartLoc, EndLoc, Data), CollapsedNum(CollapsedNum) {} /// Offset to the start of children expression arrays. @@ -599,146 +736,142 @@ } void setIterationVariable(Expr *IV) { - *std::next(child_begin(), IterationVariableOffset) = IV; + Data->getChildren()[IterationVariableOffset] = IV; } void setLastIteration(Expr *LI) { - *std::next(child_begin(), LastIterationOffset) = LI; + Data->getChildren()[LastIterationOffset] = LI; } void setCalcLastIteration(Expr *CLI) { - *std::next(child_begin(), CalcLastIterationOffset) = CLI; - } - void setPreCond(Expr *PC) { - *std::next(child_begin(), PreConditionOffset) = PC; - } - void setCond(Expr *Cond) { - *std::next(child_begin(), CondOffset) = Cond; + Data->getChildren()[CalcLastIterationOffset] = CLI; } - void setInit(Expr *Init) { *std::next(child_begin(), InitOffset) = Init; } - void setInc(Expr *Inc) { *std::next(child_begin(), IncOffset) = Inc; } + void setPreCond(Expr *PC) { Data->getChildren()[PreConditionOffset] = PC; } + void setCond(Expr *Cond) { Data->getChildren()[CondOffset] = Cond; } + void setInit(Expr *Init) { Data->getChildren()[InitOffset] = Init; } + void setInc(Expr *Inc) { Data->getChildren()[IncOffset] = Inc; } void setPreInits(Stmt *PreInits) { - *std::next(child_begin(), PreInitsOffset) = PreInits; + Data->getChildren()[PreInitsOffset] = PreInits; } void setIsLastIterVariable(Expr *IL) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), IsLastIterVariableOffset) = IL; + Data->getChildren()[IsLastIterVariableOffset] = IL; } void setLowerBoundVariable(Expr *LB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), LowerBoundVariableOffset) = LB; + Data->getChildren()[LowerBoundVariableOffset] = LB; } void setUpperBoundVariable(Expr *UB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), UpperBoundVariableOffset) = UB; + Data->getChildren()[UpperBoundVariableOffset] = UB; } void setStrideVariable(Expr *ST) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), StrideVariableOffset) = ST; + Data->getChildren()[StrideVariableOffset] = ST; } void setEnsureUpperBound(Expr *EUB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), EnsureUpperBoundOffset) = EUB; + Data->getChildren()[EnsureUpperBoundOffset] = EUB; } void setNextLowerBound(Expr *NLB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), NextLowerBoundOffset) = NLB; + Data->getChildren()[NextLowerBoundOffset] = NLB; } void setNextUpperBound(Expr *NUB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), NextUpperBoundOffset) = NUB; + Data->getChildren()[NextUpperBoundOffset] = NUB; } void setNumIterations(Expr *NI) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - *std::next(child_begin(), NumIterationsOffset) = NI; + Data->getChildren()[NumIterationsOffset] = NI; } void setPrevLowerBoundVariable(Expr *PrevLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), PrevLowerBoundVariableOffset) = PrevLB; + Data->getChildren()[PrevLowerBoundVariableOffset] = PrevLB; } void setPrevUpperBoundVariable(Expr *PrevUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), PrevUpperBoundVariableOffset) = PrevUB; + Data->getChildren()[PrevUpperBoundVariableOffset] = PrevUB; } void setDistInc(Expr *DistInc) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), DistIncOffset) = DistInc; + Data->getChildren()[DistIncOffset] = DistInc; } void setPrevEnsureUpperBound(Expr *PrevEUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), PrevEnsureUpperBoundOffset) = PrevEUB; + Data->getChildren()[PrevEnsureUpperBoundOffset] = PrevEUB; } void setCombinedLowerBoundVariable(Expr *CombLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedLowerBoundVariableOffset) = CombLB; + Data->getChildren()[CombinedLowerBoundVariableOffset] = CombLB; } void setCombinedUpperBoundVariable(Expr *CombUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedUpperBoundVariableOffset) = CombUB; + Data->getChildren()[CombinedUpperBoundVariableOffset] = CombUB; } void setCombinedEnsureUpperBound(Expr *CombEUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedEnsureUpperBoundOffset) = CombEUB; + Data->getChildren()[CombinedEnsureUpperBoundOffset] = CombEUB; } void setCombinedInit(Expr *CombInit) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedInitOffset) = CombInit; + Data->getChildren()[CombinedInitOffset] = CombInit; } void setCombinedCond(Expr *CombCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedConditionOffset) = CombCond; + Data->getChildren()[CombinedConditionOffset] = CombCond; } void setCombinedNextLowerBound(Expr *CombNLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedNextLowerBoundOffset) = CombNLB; + Data->getChildren()[CombinedNextLowerBoundOffset] = CombNLB; } void setCombinedNextUpperBound(Expr *CombNUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - *std::next(child_begin(), CombinedNextUpperBoundOffset) = CombNUB; + Data->getChildren()[CombinedNextUpperBoundOffset] = CombNUB; } void setCombinedDistCond(Expr *CombDistCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); - *std::next(child_begin(), CombinedDistConditionOffset) = CombDistCond; + Data->getChildren()[CombinedDistConditionOffset] = CombDistCond; } void setCombinedParForInDistCond(Expr *CombParForInDistCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); - *std::next(child_begin(), - CombinedParForInDistConditionOffset) = CombParForInDistCond; + Data->getChildren()[CombinedParForInDistConditionOffset] = + CombParForInDistCond; } void setCounters(ArrayRef A); void setPrivateCounters(ArrayRef A); @@ -925,178 +1058,144 @@ unsigned getCollapsedNumber() const { return CollapsedNum; } Expr *getIterationVariable() const { - return const_cast(reinterpret_cast( - *std::next(child_begin(), IterationVariableOffset))); + return cast(Data->getChildren()[IterationVariableOffset]); } Expr *getLastIteration() const { - return const_cast(reinterpret_cast( - *std::next(child_begin(), LastIterationOffset))); + return cast(Data->getChildren()[LastIterationOffset]); } Expr *getCalcLastIteration() const { - return const_cast(reinterpret_cast( - *std::next(child_begin(), CalcLastIterationOffset))); + return cast(Data->getChildren()[CalcLastIterationOffset]); } Expr *getPreCond() const { - return const_cast(reinterpret_cast( - *std::next(child_begin(), PreConditionOffset))); - } - Expr *getCond() const { - return const_cast( - reinterpret_cast(*std::next(child_begin(), CondOffset))); - } - Expr *getInit() const { - return const_cast( - reinterpret_cast(*std::next(child_begin(), InitOffset))); - } - Expr *getInc() const { - return const_cast( - reinterpret_cast(*std::next(child_begin(), IncOffset))); + return cast(Data->getChildren()[PreConditionOffset]); } + Expr *getCond() const { return cast(Data->getChildren()[CondOffset]); } + Expr *getInit() const { return cast(Data->getChildren()[InitOffset]); } + Expr *getInc() const { return cast(Data->getChildren()[IncOffset]); } const Stmt *getPreInits() const { - return *std::next(child_begin(), PreInitsOffset); + return Data->getChildren()[PreInitsOffset]; } - Stmt *getPreInits() { return *std::next(child_begin(), PreInitsOffset); } + Stmt *getPreInits() { return Data->getChildren()[PreInitsOffset]; } Expr *getIsLastIterVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), IsLastIterVariableOffset))); + return cast(Data->getChildren()[IsLastIterVariableOffset]); } Expr *getLowerBoundVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), LowerBoundVariableOffset))); + return cast(Data->getChildren()[LowerBoundVariableOffset]); } Expr *getUpperBoundVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), UpperBoundVariableOffset))); + return cast(Data->getChildren()[UpperBoundVariableOffset]); } Expr *getStrideVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), StrideVariableOffset))); + return cast(Data->getChildren()[StrideVariableOffset]); } Expr *getEnsureUpperBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), EnsureUpperBoundOffset))); + return cast(Data->getChildren()[EnsureUpperBoundOffset]); } Expr *getNextLowerBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), NextLowerBoundOffset))); + return cast(Data->getChildren()[NextLowerBoundOffset]); } Expr *getNextUpperBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), NextUpperBoundOffset))); + return cast(Data->getChildren()[NextUpperBoundOffset]); } Expr *getNumIterations() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), NumIterationsOffset))); + return cast(Data->getChildren()[NumIterationsOffset]); } Expr *getPrevLowerBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), PrevLowerBoundVariableOffset))); + return cast(Data->getChildren()[PrevLowerBoundVariableOffset]); } Expr *getPrevUpperBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), PrevUpperBoundVariableOffset))); + return cast(Data->getChildren()[PrevUpperBoundVariableOffset]); } Expr *getDistInc() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), DistIncOffset))); + return cast(Data->getChildren()[DistIncOffset]); } Expr *getPrevEnsureUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), PrevEnsureUpperBoundOffset))); + return cast(Data->getChildren()[PrevEnsureUpperBoundOffset]); } Expr *getCombinedLowerBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedLowerBoundVariableOffset))); + return cast(Data->getChildren()[CombinedLowerBoundVariableOffset]); } Expr *getCombinedUpperBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedUpperBoundVariableOffset))); + return cast(Data->getChildren()[CombinedUpperBoundVariableOffset]); } Expr *getCombinedEnsureUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedEnsureUpperBoundOffset))); + return cast(Data->getChildren()[CombinedEnsureUpperBoundOffset]); } Expr *getCombinedInit() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedInitOffset))); + return cast(Data->getChildren()[CombinedInitOffset]); } Expr *getCombinedCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedConditionOffset))); + return cast(Data->getChildren()[CombinedConditionOffset]); } Expr *getCombinedNextLowerBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedNextLowerBoundOffset))); + return cast(Data->getChildren()[CombinedNextLowerBoundOffset]); } Expr *getCombinedNextUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedNextUpperBoundOffset))); + return cast(Data->getChildren()[CombinedNextUpperBoundOffset]); } Expr *getCombinedDistCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedDistConditionOffset))); + return cast(Data->getChildren()[CombinedDistConditionOffset]); } Expr *getCombinedParForInDistCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); - return const_cast(reinterpret_cast( - *std::next(child_begin(), CombinedParForInDistConditionOffset))); + return cast(Data->getChildren()[CombinedParForInDistConditionOffset]); } /// Try to find the next loop sub-statement in the specified statement \p /// CurStmt. @@ -1206,27 +1305,30 @@ /// class OMPSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPSimdDirectiveClass, llvm::omp::OMPD_simd, - StartLoc, EndLoc, CollapsedNum, NumClauses) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPSimdDirectiveClass, llvm::omp::OMPD_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -1271,38 +1373,39 @@ /// class OMPForDirective : public OMPLoopDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPForDirectiveClass, llvm::omp::OMPD_for, - StartLoc, EndLoc, CollapsedNum, NumClauses), - HasCancel(false) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPForDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPForDirectiveClass, llvm::omp::OMPD_for, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses), - HasCancel(false) {} + Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren(getCollapsedNumber(), + llvm::omp::OMPD_for)] = E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -1338,8 +1441,13 @@ unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this)->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -1360,28 +1468,31 @@ /// class OMPForSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPForSimdDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPForSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -1426,38 +1537,35 @@ /// class OMPSectionsDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; /// true if current directive has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPSectionsDirectiveClass, llvm::omp::OMPD_sections, StartLoc, EndLoc, - NumClauses, 1), - HasCancel(false) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPSectionsDirective(unsigned NumClauses) + explicit OMPSectionsDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPSectionsDirectiveClass, llvm::omp::OMPD_sections, SourceLocation(), - SourceLocation(), NumClauses, 1), - HasCancel(false) {} + SourceLocation(), Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -1489,8 +1597,12 @@ unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[0]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this)->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -1508,27 +1620,32 @@ /// class OMPSectionDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc) + OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc, + OMPChildren *Data) : OMPExecutableDirective(this, OMPSectionDirectiveClass, - llvm::omp::OMPD_section, StartLoc, EndLoc, 0, 1), - HasCancel(false) {} + llvm::omp::OMPD_section, StartLoc, EndLoc, + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPSectionDirective() + explicit OMPSectionDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPSectionDirectiveClass, llvm::omp::OMPD_section, SourceLocation(), - SourceLocation(), 0, 1), - HasCancel(false) {} + SourceLocation(), Data) {} public: /// Creates directive. @@ -1571,26 +1688,28 @@ /// class OMPSingleDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPSingleDirectiveClass, - llvm::omp::OMPD_single, StartLoc, EndLoc, - NumClauses, 1) {} + llvm::omp::OMPD_single, StartLoc, EndLoc, Data) { + } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPSingleDirective(unsigned NumClauses) + explicit OMPSingleDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPSingleDirectiveClass, llvm::omp::OMPD_single, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -1627,22 +1746,28 @@ /// class OMPMasterDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc) + OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc, + OMPChildren *Data) : OMPExecutableDirective(this, OMPMasterDirectiveClass, - llvm::omp::OMPD_master, StartLoc, EndLoc, 0, 1) { + llvm::omp::OMPD_master, StartLoc, EndLoc, Data) { } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPMasterDirective() + explicit OMPMasterDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPMasterDirectiveClass, llvm::omp::OMPD_master, SourceLocation(), - SourceLocation(), 0, 1) {} + SourceLocation(), Data) {} public: /// Creates directive. @@ -1676,6 +1801,7 @@ /// class OMPCriticalDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Name of the directive. DeclarationNameInfo DirName; /// Build directive with the given start and end location. @@ -1683,24 +1809,24 @@ /// \param Name Name of the directive. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc, - SourceLocation EndLoc, unsigned NumClauses) + SourceLocation EndLoc, OMPChildren *Data) : OMPExecutableDirective(this, OMPCriticalDirectiveClass, llvm::omp::OMPD_critical, StartLoc, EndLoc, - NumClauses, 1), + Data), DirName(Name) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPCriticalDirective(unsigned NumClauses) + explicit OMPCriticalDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPCriticalDirectiveClass, llvm::omp::OMPD_critical, SourceLocation(), - SourceLocation(), NumClauses, 1), - DirName() {} + SourceLocation(), Data) {} /// Set name of the directive. /// @@ -1751,40 +1877,41 @@ /// class OMPParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; /// true if current region has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPParallelForDirectiveClass, llvm::omp::OMPD_parallel_for, StartLoc, EndLoc, - CollapsedNum, NumClauses), - HasCancel(false) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPParallelForDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPParallelForDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPParallelForDirectiveClass, llvm::omp::OMPD_parallel_for, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses), - HasCancel(false) {} + SourceLocation(), CollapsedNum, Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren(getCollapsedNumber(), + llvm::omp::OMPD_parallel_for)] = E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -1822,8 +1949,14 @@ EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_parallel_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -1845,29 +1978,31 @@ /// class OMPParallelForSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPParallelForSimdDirectiveClass, llvm::omp::OMPD_parallel_for_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPParallelForSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + explicit OMPParallelForSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPParallelForSimdDirectiveClass, llvm::omp::OMPD_parallel_for_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -1912,25 +2047,21 @@ /// class OMPParallelMasterDirective : public OMPExecutableDirective { friend class ASTStmtReader; - - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; OMPParallelMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass, llvm::omp::OMPD_parallel_master, StartLoc, - EndLoc, NumClauses, 1) {} + EndLoc, Data) {} - explicit OMPParallelMasterDirective(unsigned NumClauses) + explicit OMPParallelMasterDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass, llvm::omp::OMPD_parallel_master, - SourceLocation(), SourceLocation(), NumClauses, - 1) {} + SourceLocation(), SourceLocation(), Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } public: /// Creates directive with a list of \a Clauses. @@ -1957,8 +2088,13 @@ CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[0]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelMasterDirectiveClass; @@ -1976,39 +2112,35 @@ /// class OMPParallelSectionsDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; /// true if current directive has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass, llvm::omp::OMPD_parallel_sections, StartLoc, - EndLoc, NumClauses, 1), - HasCancel(false) {} + EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPParallelSectionsDirective(unsigned NumClauses) + explicit OMPParallelSectionsDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass, llvm::omp::OMPD_parallel_sections, - SourceLocation(), SourceLocation(), NumClauses, - 1), - HasCancel(false) {} + SourceLocation(), SourceLocation(), Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -2040,8 +2172,13 @@ CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[0]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -2061,31 +2198,30 @@ /// class OMPTaskDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// true if this directive has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTaskDirectiveClass, - llvm::omp::OMPD_task, StartLoc, EndLoc, - NumClauses, 1), - HasCancel(false) {} + llvm::omp::OMPD_task, StartLoc, EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTaskDirective(unsigned NumClauses) + explicit OMPTaskDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTaskDirectiveClass, llvm::omp::OMPD_task, SourceLocation(), - SourceLocation(), NumClauses, 1), - HasCancel(false) {} + SourceLocation(), Data) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -2130,6 +2266,7 @@ /// class OMPTaskyieldDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. @@ -2137,15 +2274,14 @@ /// OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, - llvm::omp::OMPD_taskyield, StartLoc, EndLoc, 0, - 0) {} + llvm::omp::OMPD_taskyield, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskyieldDirective() : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, llvm::omp::OMPD_taskyield, SourceLocation(), - SourceLocation(), 0, 0) {} + SourceLocation()) {} public: /// Creates directive. @@ -2176,6 +2312,7 @@ /// class OMPBarrierDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. @@ -2183,15 +2320,14 @@ /// OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(this, OMPBarrierDirectiveClass, - llvm::omp::OMPD_barrier, StartLoc, EndLoc, 0, - 0) {} + llvm::omp::OMPD_barrier, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPBarrierDirective() : OMPExecutableDirective(this, OMPBarrierDirectiveClass, llvm::omp::OMPD_barrier, SourceLocation(), - SourceLocation(), 0, 0) {} + SourceLocation()) {} public: /// Creates directive. @@ -2222,6 +2358,7 @@ /// class OMPTaskwaitDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. @@ -2229,15 +2366,14 @@ /// OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, - llvm::omp::OMPD_taskwait, StartLoc, EndLoc, 0, - 0) {} + llvm::omp::OMPD_taskwait, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskwaitDirective() : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, llvm::omp::OMPD_taskwait, SourceLocation(), - SourceLocation(), 0, 0) {} + SourceLocation()) {} public: /// Creates directive. @@ -2268,30 +2404,31 @@ /// class OMPTaskgroupDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTaskgroupDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTaskgroupDirectiveClass, llvm::omp::OMPD_taskgroup, StartLoc, EndLoc, - NumClauses, 2) {} + Data) {} /// Build an empty directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPTaskgroupDirective(unsigned NumClauses) + explicit OMPTaskgroupDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTaskgroupDirectiveClass, llvm::omp::OMPD_taskgroup, SourceLocation(), - SourceLocation(), NumClauses, 2) {} + SourceLocation(), Data) {} /// Sets the task_reduction return variable. - void setReductionRef(Expr *RR) { - *std::next(child_begin(), 1) = RR; - } + void setReductionRef(Expr *RR) { Data->getChildren()[0] = RR; } public: /// Creates directive. @@ -2319,11 +2456,9 @@ /// Returns reference to the task_reduction return variable. const Expr *getReductionRef() const { - return static_cast(*std::next(child_begin(), 1)); - } - Expr *getReductionRef() { - return static_cast(*std::next(child_begin(), 1)); + return const_cast(this)->getReductionRef(); } + Expr *getReductionRef() { return cast_or_null(Data->getChildren()[0]); } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskgroupDirectiveClass; @@ -2342,26 +2477,27 @@ /// FlushClause. class OMPFlushDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPFlushDirectiveClass, - llvm::omp::OMPD_flush, StartLoc, EndLoc, - NumClauses, 0) {} + llvm::omp::OMPD_flush, StartLoc, EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPFlushDirective(unsigned NumClauses) + explicit OMPFlushDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPFlushDirectiveClass, llvm::omp::OMPD_flush, SourceLocation(), - SourceLocation(), NumClauses, 0) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2399,27 +2535,29 @@ /// 'a' with dependence type 'in' and a list with 'x' and 'y' locators. class OMPDepobjDirective final : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPDepobjDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPDepobjDirectiveClass, - llvm::omp::OMPD_depobj, StartLoc, EndLoc, - NumClauses, 0) {} + llvm::omp::OMPD_depobj, StartLoc, EndLoc, Data) { + } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPDepobjDirective(unsigned NumClauses) + explicit OMPDepobjDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPDepobjDirectiveClass, llvm::omp::OMPD_depobj, SourceLocation(), - SourceLocation(), NumClauses, 0) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2456,26 +2594,28 @@ /// class OMPOrderedDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPOrderedDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPOrderedDirectiveClass, llvm::omp::OMPD_ordered, StartLoc, EndLoc, - NumClauses, 1) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPOrderedDirective(unsigned NumClauses) + explicit OMPOrderedDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPOrderedDirectiveClass, llvm::omp::OMPD_ordered, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive. @@ -2494,9 +2634,11 @@ /// /// \param C AST context. /// \param NumClauses Number of clauses. + /// \param IsStandalone true, if the the standalone directive is created. /// static OMPOrderedDirective *CreateEmpty(const ASTContext &C, - unsigned NumClauses, EmptyShell); + unsigned NumClauses, + bool IsStandalone, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPOrderedDirectiveClass; @@ -2512,6 +2654,7 @@ /// class OMPAtomicDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Used for 'atomic update' or 'atomic capture' constructs. They may /// have atomic expressions of forms /// \code @@ -2521,7 +2664,7 @@ /// This field is true for the first form of the expression and false for the /// second. Required for correct codegen of non-associative operations (like /// << or >>). - bool IsXLHSInRHSPart; + bool IsXLHSInRHSPart = false; /// Used for 'atomic update' or 'atomic capture' constructs. They may /// have atomic expressions of forms /// \code @@ -2530,41 +2673,40 @@ /// \endcode /// This field is true for the first(postfix) form of the expression and false /// otherwise. - bool IsPostfixUpdate; + bool IsPostfixUpdate = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPAtomicDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPAtomicDirectiveClass, - llvm::omp::OMPD_atomic, StartLoc, EndLoc, - NumClauses, 5), - IsXLHSInRHSPart(false), IsPostfixUpdate(false) {} + llvm::omp::OMPD_atomic, StartLoc, EndLoc, Data) { + } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPAtomicDirective(unsigned NumClauses) + explicit OMPAtomicDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPAtomicDirectiveClass, llvm::omp::OMPD_atomic, SourceLocation(), - SourceLocation(), NumClauses, 5), - IsXLHSInRHSPart(false), IsPostfixUpdate(false) {} + SourceLocation(), Data) {} /// Set 'x' part of the associated expression/statement. - void setX(Expr *X) { *std::next(child_begin()) = X; } + void setX(Expr *X) { Data->getChildren()[0] = X; } /// Set helper expression of the form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. - void setUpdateExpr(Expr *UE) { *std::next(child_begin(), 2) = UE; } + void setUpdateExpr(Expr *UE) { Data->getChildren()[1] = UE; } /// Set 'v' part of the associated expression/statement. - void setV(Expr *V) { *std::next(child_begin(), 3) = V; } + void setV(Expr *V) { Data->getChildren()[2] = V; } /// Set 'expr' part of the associated expression/statement. - void setExpr(Expr *E) { *std::next(child_begin(), 4) = E; } + void setExpr(Expr *E) { Data->getChildren()[3] = E; } public: /// Creates directive with a list of \a Clauses and 'x', 'v' and 'expr' @@ -2601,18 +2743,16 @@ unsigned NumClauses, EmptyShell); /// Get 'x' part of the associated expression/statement. - Expr *getX() { return cast_or_null(*std::next(child_begin())); } + Expr *getX() { return cast_or_null(Data->getChildren()[0]); } const Expr *getX() const { - return cast_or_null(*std::next(child_begin())); + return cast_or_null(Data->getChildren()[0]); } /// Get helper expression of the form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. - Expr *getUpdateExpr() { - return cast_or_null(*std::next(child_begin(), 2)); - } + Expr *getUpdateExpr() { return cast_or_null(Data->getChildren()[1]); } const Expr *getUpdateExpr() const { - return cast_or_null(*std::next(child_begin(), 2)); + return cast_or_null(Data->getChildren()[1]); } /// Return true if helper update expression has form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form @@ -2622,14 +2762,14 @@ /// 'x', false if 'v' must be updated to the new value of 'x'. bool isPostfixUpdate() const { return IsPostfixUpdate; } /// Get 'v' part of the associated expression/statement. - Expr *getV() { return cast_or_null(*std::next(child_begin(), 3)); } + Expr *getV() { return cast_or_null(Data->getChildren()[2]); } const Expr *getV() const { - return cast_or_null(*std::next(child_begin(), 3)); + return cast_or_null(Data->getChildren()[2]); } /// Get 'expr' part of the associated expression/statement. - Expr *getExpr() { return cast_or_null(*std::next(child_begin(), 4)); } + Expr *getExpr() { return cast_or_null(Data->getChildren()[3]); } const Expr *getExpr() const { - return cast_or_null(*std::next(child_begin(), 4)); + return cast_or_null(Data->getChildren()[3]); } static bool classof(const Stmt *T) { @@ -2647,26 +2787,28 @@ /// class OMPTargetDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetDirectiveClass, - llvm::omp::OMPD_target, StartLoc, EndLoc, - NumClauses, 1) {} + llvm::omp::OMPD_target, StartLoc, EndLoc, Data) { + } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetDirective(unsigned NumClauses) + explicit OMPTargetDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetDirectiveClass, llvm::omp::OMPD_target, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2706,26 +2848,28 @@ /// class OMPTargetDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. - /// \param NumClauses The number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetDataDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetDataDirectiveClass, llvm::omp::OMPD_target_data, StartLoc, EndLoc, - NumClauses, 1) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetDataDirective(unsigned NumClauses) + explicit OMPTargetDataDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetDataDirectiveClass, llvm::omp::OMPD_target_data, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2764,27 +2908,28 @@ /// class OMPTargetEnterDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. - /// \param NumClauses The number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetEnterDataDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetEnterDataDirectiveClass, llvm::omp::OMPD_target_enter_data, StartLoc, - EndLoc, NumClauses, /*NumChildren=*/1) {} + EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetEnterDataDirective(unsigned NumClauses) + explicit OMPTargetEnterDataDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetEnterDataDirectiveClass, llvm::omp::OMPD_target_enter_data, - SourceLocation(), SourceLocation(), NumClauses, - /*NumChildren=*/1) {} + SourceLocation(), SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2823,27 +2968,28 @@ /// class OMPTargetExitDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. - /// \param NumClauses The number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetExitDataDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetExitDataDirectiveClass, llvm::omp::OMPD_target_exit_data, StartLoc, - EndLoc, NumClauses, /*NumChildren=*/1) {} + EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetExitDataDirective(unsigned NumClauses) + explicit OMPTargetExitDataDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetExitDataDirectiveClass, llvm::omp::OMPD_target_exit_data, - SourceLocation(), SourceLocation(), NumClauses, - /*NumChildren=*/1) {} + SourceLocation(), SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -2881,9 +3027,7 @@ /// class OMPTargetParallelDirective : public OMPExecutableDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; @@ -2891,26 +3035,26 @@ /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetParallelDirectiveClass, llvm::omp::OMPD_target_parallel, StartLoc, - EndLoc, NumClauses, /*NumChildren=*/1) {} + EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetParallelDirective(unsigned NumClauses) + explicit OMPTargetParallelDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetParallelDirectiveClass, llvm::omp::OMPD_target_parallel, - SourceLocation(), SourceLocation(), NumClauses, - /*NumChildren=*/1) {} + SourceLocation(), SourceLocation(), Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -2941,8 +3085,13 @@ CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[0]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -2963,41 +3112,42 @@ /// class OMPTargetParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; /// true if current region has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTargetParallelForDirectiveClass, llvm::omp::OMPD_target_parallel_for, StartLoc, EndLoc, - CollapsedNum, NumClauses), - HasCancel(false) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetParallelForDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetParallelForDirectiveClass, llvm::omp::OMPD_target_parallel_for, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses), - HasCancel(false) {} + SourceLocation(), CollapsedNum, Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_target_parallel_for)] = E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -3035,8 +3185,14 @@ EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_target_parallel_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -3056,26 +3212,27 @@ /// class OMPTeamsDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTeamsDirectiveClass, - llvm::omp::OMPD_teams, StartLoc, EndLoc, - NumClauses, 1) {} + llvm::omp::OMPD_teams, StartLoc, EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTeamsDirective(unsigned NumClauses) + explicit OMPTeamsDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTeamsDirectiveClass, llvm::omp::OMPD_teams, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -3114,25 +3271,28 @@ /// In this example a cancellation point is created for innermost 'for' region. class OMPCancellationPointDirective : public OMPExecutableDirective { friend class ASTStmtReader; - OpenMPDirectiveKind CancelRegion; + friend class OMPExecutableDirective; + OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPCancellationPointDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(this, OMPCancellationPointDirectiveClass, llvm::omp::OMPD_cancellation_point, StartLoc, - EndLoc, 0, 0), - CancelRegion(llvm::omp::OMPD_unknown) {} + EndLoc) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPCancellationPointDirective() : OMPExecutableDirective(this, OMPCancellationPointDirectiveClass, llvm::omp::OMPD_cancellation_point, - SourceLocation(), SourceLocation(), 0, 0), - CancelRegion(llvm::omp::OMPD_unknown) {} + SourceLocation(), SourceLocation()) {} /// Set cancel region for current cancellation point. /// \param CR Cancellation region. @@ -3173,28 +3333,29 @@ /// In this example a cancel is created for innermost 'for' region. class OMPCancelDirective : public OMPExecutableDirective { friend class ASTStmtReader; - OpenMPDirectiveKind CancelRegion; + friend class OMPExecutableDirective; + OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPCancelDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPCancelDirectiveClass, - llvm::omp::OMPD_cancel, StartLoc, EndLoc, - NumClauses, 0), - CancelRegion(llvm::omp::OMPD_unknown) {} + llvm::omp::OMPD_cancel, StartLoc, EndLoc, Data) { + } /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - explicit OMPCancelDirective(unsigned NumClauses) + explicit OMPCancelDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPCancelDirectiveClass, llvm::omp::OMPD_cancel, SourceLocation(), - SourceLocation(), NumClauses, 0), - CancelRegion(llvm::omp::OMPD_unknown) {} + SourceLocation(), Data) {} /// Set cancel region for current cancellation point. /// \param CR Cancellation region. @@ -3239,33 +3400,34 @@ /// class OMPTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop, StartLoc, EndLoc, - CollapsedNum, NumClauses), - HasCancel(false) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPTaskLoopDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPTaskLoopDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses), - HasCancel(false) {} + SourceLocation(), CollapsedNum, Data) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -3317,28 +3479,31 @@ /// class OMPTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTaskLoopSimdDirectiveClass, llvm::omp::OMPD_taskloop_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPTaskLoopSimdDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPTaskLoopSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTaskLoopSimdDirectiveClass, llvm::omp::OMPD_taskloop_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -3384,34 +3549,34 @@ /// class OMPMasterTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPMasterTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPMasterTaskLoopDirectiveClass, llvm::omp::OMPD_master_taskloop, StartLoc, EndLoc, - CollapsedNum, NumClauses), - HasCancel(false) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPMasterTaskLoopDirective(unsigned CollapsedNum, - unsigned NumClauses) + explicit OMPMasterTaskLoopDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPMasterTaskLoopDirectiveClass, llvm::omp::OMPD_master_taskloop, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses), - HasCancel(false) {} + SourceLocation(), CollapsedNum, Data) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -3464,29 +3629,32 @@ /// class OMPMasterTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPMasterTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_master_taskloop_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPMasterTaskLoopSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_master_taskloop_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \p Clauses. @@ -3532,36 +3700,37 @@ /// class OMPParallelMasterTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. - bool HasCancel; + bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelMasterTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPParallelMasterTaskLoopDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop, StartLoc, - EndLoc, CollapsedNum, NumClauses), - HasCancel(false) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPParallelMasterTaskLoopDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPParallelMasterTaskLoopDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses), - HasCancel(false) {} + Data) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -3615,32 +3784,35 @@ /// class OMPParallelMasterTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPParallelMasterTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPParallelMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop_simd, - StartLoc, EndLoc, CollapsedNum, NumClauses) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPParallelMasterTaskLoopSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPParallelMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \p Clauses. @@ -3684,29 +3856,32 @@ /// class OMPDistributeDirective : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeDirectiveClass, llvm::omp::OMPD_distribute, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPDistributeDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPDistributeDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeDirectiveClass, llvm::omp::OMPD_distribute, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -3751,26 +3926,28 @@ /// class OMPTargetUpdateDirective : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. - /// \param NumClauses The number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetUpdateDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetUpdateDirectiveClass, llvm::omp::OMPD_target_update, StartLoc, EndLoc, - NumClauses, 1) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetUpdateDirective(unsigned NumClauses) + explicit OMPTargetUpdateDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetUpdateDirectiveClass, llvm::omp::OMPD_target_update, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -3810,9 +3987,7 @@ /// class OMPDistributeParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; @@ -3821,31 +3996,34 @@ /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeParallelForDirectiveClass, llvm::omp::OMPD_distribute_parallel_for, StartLoc, - EndLoc, CollapsedNum, NumClauses), - HasCancel(false) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPDistributeParallelForDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeParallelForDirectiveClass, llvm::omp::OMPD_distribute_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses), - HasCancel(false) {} + Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_distribute_parallel_for)] = E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -3883,8 +4061,14 @@ EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_distribute_parallel_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -3905,33 +4089,36 @@ /// class OMPDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_distribute_parallel_for_simd, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPDistributeParallelForSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_distribute_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -3974,30 +4161,32 @@ /// class OMPDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeSimdDirectiveClass, llvm::omp::OMPD_distribute_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPDistributeSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + explicit OMPDistributeSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPDistributeSimdDirectiveClass, llvm::omp::OMPD_distribute_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4042,32 +4231,35 @@ /// class OMPTargetParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTargetParallelForSimdDirectiveClass, llvm::omp::OMPD_target_parallel_for_simd, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetParallelForSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetParallelForSimdDirectiveClass, llvm::omp::OMPD_target_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4112,29 +4304,32 @@ /// class OMPTargetSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTargetSimdDirectiveClass, llvm::omp::OMPD_target_simd, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPTargetSimdDirective(unsigned CollapsedNum, unsigned NumClauses) + explicit OMPTargetSimdDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTargetSimdDirectiveClass, llvm::omp::OMPD_target_simd, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4178,30 +4373,32 @@ /// class OMPTeamsDistributeDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTeamsDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeDirectiveClass, llvm::omp::OMPD_teams_distribute, StartLoc, EndLoc, - CollapsedNum, NumClauses) {} + CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - explicit OMPTeamsDistributeDirective(unsigned CollapsedNum, - unsigned NumClauses) + explicit OMPTeamsDistributeDirective(unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeDirectiveClass, llvm::omp::OMPD_teams_distribute, SourceLocation(), - SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4246,32 +4443,35 @@ /// class OMPTeamsDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTeamsDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_simd, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTeamsDistributeSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4318,33 +4518,36 @@ class OMPTeamsDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for_simd, - StartLoc, EndLoc, CollapsedNum, NumClauses) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTeamsDistributeParallelForSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4388,9 +4591,7 @@ /// class OMPTeamsDistributeParallelForDirective final : public OMPLoopDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; @@ -4399,32 +4600,36 @@ /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTeamsDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for, - StartLoc, EndLoc, CollapsedNum, NumClauses), - HasCancel(false) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTeamsDistributeParallelForDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses), - HasCancel(false) {} + Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)] = + E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -4460,8 +4665,14 @@ EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -4481,26 +4692,28 @@ /// class OMPTargetTeamsDirective final : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetTeamsDirectiveClass, llvm::omp::OMPD_target_teams, StartLoc, EndLoc, - NumClauses, 1) {} + Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPTargetTeamsDirective(unsigned NumClauses) + explicit OMPTargetTeamsDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPTargetTeamsDirectiveClass, llvm::omp::OMPD_target_teams, SourceLocation(), - SourceLocation(), NumClauses, 1) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4540,32 +4753,35 @@ /// class OMPTargetTeamsDistributeDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetTeamsDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective(this, OMPTargetTeamsDistributeDirectiveClass, llvm::omp::OMPD_target_teams_distribute, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetTeamsDistributeDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetTeamsDistributeDirectiveClass, llvm::omp::OMPD_target_teams_distribute, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4610,9 +4826,7 @@ class OMPTargetTeamsDistributeParallelForDirective final : public OMPLoopDirective { friend class ASTStmtReader; - /// Special reference expression for handling task reduction. Used to store - /// the taskgroup descriptor returned by the runtime functions. - Expr *TaskRedRef = nullptr; + friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; @@ -4621,33 +4835,37 @@ /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetTeamsDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for, - StartLoc, EndLoc, CollapsedNum, NumClauses), - HasCancel(false) {} + StartLoc, EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetTeamsDistributeParallelForDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective( this, OMPTargetTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for, - SourceLocation(), SourceLocation(), CollapsedNum, NumClauses), - HasCancel(false) {} + SourceLocation(), SourceLocation(), CollapsedNum, Data) {} /// Sets special task reduction descriptor. - void setTaskReductionRefExpr(Expr *E) { TaskRedRef = E; } + void setTaskReductionRefExpr(Expr *E) { + Data->getChildren()[numLoopChildren( + getCollapsedNumber(), + llvm::omp::OMPD_target_teams_distribute_parallel_for)] = E; + } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } @@ -4683,8 +4901,15 @@ EmptyShell); /// Returns special task reduction reference expression. - Expr *getTaskReductionRefExpr() { return TaskRedRef; } - const Expr *getTaskReductionRefExpr() const { return TaskRedRef; } + Expr *getTaskReductionRefExpr() { + return cast_or_null(Data->getChildren()[numLoopChildren( + getCollapsedNumber(), + llvm::omp::OMPD_target_teams_distribute_parallel_for)]); + } + const Expr *getTaskReductionRefExpr() const { + return const_cast(this) + ->getTaskReductionRefExpr(); + } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } @@ -4707,34 +4932,37 @@ class OMPTargetTeamsDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective( this, OMPTargetTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for_simd, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetTeamsDistributeParallelForSimdDirective( - unsigned CollapsedNum, unsigned NumClauses) + unsigned CollapsedNum, OMPChildren *Data) : OMPLoopDirective( this, OMPTargetTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for_simd, - SourceLocation(), SourceLocation(), CollapsedNum, NumClauses) {} + SourceLocation(), SourceLocation(), CollapsedNum, Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4779,33 +5007,36 @@ /// class OMPTargetTeamsDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPTargetTeamsDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_simd, StartLoc, - EndLoc, CollapsedNum, NumClauses) {} + EndLoc, CollapsedNum, Data) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// explicit OMPTargetTeamsDistributeSimdDirective(unsigned CollapsedNum, - unsigned NumClauses) + OMPChildren *Data) : OMPLoopDirective(this, OMPTargetTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_simd, SourceLocation(), SourceLocation(), CollapsedNum, - NumClauses) {} + Data) {} public: /// Creates directive with a list of \a Clauses. @@ -4847,26 +5078,27 @@ /// list item 'a'. class OMPScanDirective final : public OMPExecutableDirective { friend class ASTStmtReader; + friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. - /// \param NumClauses Number of clauses. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// OMPScanDirective(SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses) + OMPChildren *Data) : OMPExecutableDirective(this, OMPScanDirectiveClass, - llvm::omp::OMPD_scan, StartLoc, EndLoc, - NumClauses, 0) {} + llvm::omp::OMPD_scan, StartLoc, EndLoc, Data) {} /// Build an empty directive. + /// \param Data Data storage, containing info about associated clauses, + /// statements and child expressions. /// - /// \param NumClauses Number of clauses. - /// - explicit OMPScanDirective(unsigned NumClauses) + explicit OMPScanDirective(OMPChildren *Data) : OMPExecutableDirective(this, OMPScanDirectiveClass, llvm::omp::OMPD_scan, SourceLocation(), - SourceLocation(), NumClauses, 0) {} + SourceLocation(), Data) {} public: /// Creates directive with a list of \a Clauses. diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp --- a/clang/lib/AST/StmtOpenMP.cpp +++ b/clang/lib/AST/StmtOpenMP.cpp @@ -16,10 +16,41 @@ using namespace clang; using namespace llvm::omp; -void OMPExecutableDirective::setClauses(ArrayRef Clauses) { - assert(Clauses.size() == getNumClauses() && +void OMPChildren::setClauses(ArrayRef Clauses) { + assert(Clauses.size() == NumClauses && "Number of clauses is not the same as the preallocated buffer"); - std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); + llvm::copy(Clauses, getTrailingObjects()); +} + +MutableArrayRef OMPChildren::getChildren() { + return llvm::makeMutableArrayRef(getTrailingObjects(), NumChildren); +} + +OMPChildren *OMPChildren::Create(const ASTContext &C, + ArrayRef Clauses) { + auto *Data = CreateEmpty(C, Clauses.size()); + Data->setClauses(Clauses); + return Data; +} + +OMPChildren *OMPChildren::Create(const ASTContext &C, + ArrayRef Clauses, Stmt *S, + unsigned NumChildren) { + auto *Data = CreateEmpty(C, Clauses.size(), S, NumChildren); + Data->setClauses(Clauses); + if (S) + Data->setAssociatedStmt(S); + return Data; +} + +OMPChildren *OMPChildren::CreateEmpty(const ASTContext &C, unsigned NumClauses, + bool HasAssociatedStmt, + unsigned NumChildren) { + void *Mem = + C.Allocate(totalSizeToAlloc( + NumClauses, NumChildren + (HasAssociatedStmt ? 1 : 0)), + alignof(OMPChildren)); + return new (Mem) OMPChildren(NumClauses, NumChildren, HasAssociatedStmt); } bool OMPExecutableDirective::isStandaloneDirective() const { @@ -30,15 +61,15 @@ isa(this) || isa(this)) return true; - return !hasAssociatedStmt() || !getAssociatedStmt(); + return !hasAssociatedStmt(); } -const Stmt *OMPExecutableDirective::getStructuredBlock() const { +Stmt *OMPExecutableDirective::getStructuredBlock() { assert(!isStandaloneDirective() && "Standalone Executable Directives don't have Structured Blocks."); if (auto *LD = dyn_cast(this)) return LD->getBody(); - return getInnermostCapturedStmt()->getCapturedStmt(); + return getRawStmt(); } Stmt *OMPLoopDirective::tryToFindNextInnerLoop(Stmt *CurStmt, @@ -87,8 +118,7 @@ Stmt *OMPLoopDirective::getBody() { // This relies on the loop form is already checked by Sema. - Stmt *Body = - getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(); + Stmt *Body = Data->getRawStmt()->IgnoreContainers(); if (auto *For = dyn_cast(Body)) { Body = For->getBody(); } else { @@ -112,32 +142,32 @@ void OMPLoopDirective::setCounters(ArrayRef A) { assert(A.size() == getCollapsedNumber() && "Number of loop counters is not the same as the collapsed number"); - std::copy(A.begin(), A.end(), getCounters().begin()); + llvm::copy(A, getCounters().begin()); } void OMPLoopDirective::setPrivateCounters(ArrayRef A) { assert(A.size() == getCollapsedNumber() && "Number of loop private counters " "is not the same as the collapsed " "number"); - std::copy(A.begin(), A.end(), getPrivateCounters().begin()); + llvm::copy(A, getPrivateCounters().begin()); } void OMPLoopDirective::setInits(ArrayRef A) { assert(A.size() == getCollapsedNumber() && "Number of counter inits is not the same as the collapsed number"); - std::copy(A.begin(), A.end(), getInits().begin()); + llvm::copy(A, getInits().begin()); } void OMPLoopDirective::setUpdates(ArrayRef A) { assert(A.size() == getCollapsedNumber() && "Number of counter updates is not the same as the collapsed number"); - std::copy(A.begin(), A.end(), getUpdates().begin()); + llvm::copy(A, getUpdates().begin()); } void OMPLoopDirective::setFinals(ArrayRef A) { assert(A.size() == getCollapsedNumber() && "Number of counter finals is not the same as the collapsed number"); - std::copy(A.begin(), A.end(), getFinals().begin()); + llvm::copy(A, getFinals().begin()); } void OMPLoopDirective::setDependentCounters(ArrayRef A) { @@ -163,14 +193,8 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPParallelDirective *Dir = - new (Mem) OMPParallelDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc); Dir->setTaskReductionRefExpr(TaskRedRef); Dir->setHasCancel(HasCancel); return Dir; @@ -179,11 +203,9 @@ OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPParallelDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true, + /*NumChildren=*/1); } OMPSimdDirective * @@ -191,14 +213,9 @@ SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPSimdDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); - OMPSimdDirective *Dir = new (Mem) - OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -222,25 +239,18 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPSimdDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); - return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_simd), CollapsedNum); } OMPForDirective *OMPForDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPForDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); - OMPForDirective *Dir = - new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_for) + 1, + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -274,11 +284,9 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPForDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); - return new (Mem) OMPForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_for) + 1, CollapsedNum); } OMPForSimdDirective * @@ -286,15 +294,9 @@ SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPForSimdDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); - OMPForSimdDirective *Dir = new (Mem) - OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_for_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -326,26 +328,18 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPForSimdDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); - return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_for_simd), CollapsedNum); } OMPSectionsDirective *OMPSectionsDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPSectionsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPSectionsDirective *Dir = - new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/1, StartLoc, + EndLoc); Dir->setTaskReductionRefExpr(TaskRedRef); Dir->setHasCancel(HasCancel); return Dir; @@ -354,11 +348,9 @@ OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPSectionsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPSectionsDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true, + /*NumChildren=*/1); } OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, @@ -366,19 +358,17 @@ SourceLocation EndLoc, Stmt *AssociatedStmt, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPSectionDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *)); - OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = + createDirective(C, llvm::None, AssociatedStmt, + /*NumChildre=*/0, StartLoc, EndLoc); Dir->setHasCancel(HasCancel); return Dir; } OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPSectionDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *)); - return new (Mem) OMPSectionDirective(); + return createEmptyDirective(C, /*NumClauses=*/0, + /*HasAssociatedStmt=*/true); } OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, @@ -386,83 +376,57 @@ SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPSingleDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPSingleDirective *Dir = - new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/0, StartLoc, + EndLoc); } OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPSingleDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPSingleDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); } OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { - unsigned Size = llvm::alignTo(sizeof(OMPMasterDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *)); - OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective(C, llvm::None, AssociatedStmt, + /*NumChildren=*/0, StartLoc, + EndLoc); } OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPMasterDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *)); - return new (Mem) OMPMasterDirective(); + return createEmptyDirective(C, /*NumClauses=*/0, + /*HasAssociatedStmt=*/true); } OMPCriticalDirective *OMPCriticalDirective::Create( const ASTContext &C, const DeclarationNameInfo &Name, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPCriticalDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPCriticalDirective *Dir = - new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/0, Name, + StartLoc, EndLoc); } OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPCriticalDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPCriticalDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); } OMPParallelForDirective *OMPParallelForDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelForDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_for)); - OMPParallelForDirective *Dir = new (Mem) - OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_parallel_for) + 1, StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -495,27 +459,19 @@ OMPParallelForDirective * OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelForDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_for)); - return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_parallel_for) + 1, CollapsedNum); } OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelForSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); - OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_parallel_for_simd), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -547,51 +503,33 @@ OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelForSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); - return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_parallel_for_simd), CollapsedNum); } OMPParallelMasterDirective *OMPParallelMasterDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - auto *Dir = - new (Mem) OMPParallelMasterDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc); Dir->setTaskReductionRefExpr(TaskRedRef); return Dir; } -OMPParallelMasterDirective *OMPParallelMasterDirective::CreateEmpty(const ASTContext &C, - unsigned NumClauses, - EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPParallelMasterDirective(NumClauses); +OMPParallelMasterDirective * +OMPParallelMasterDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, EmptyShell) { + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1); } OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelSectionsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPParallelSectionsDirective *Dir = - new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc); Dir->setTaskReductionRefExpr(TaskRedRef); Dir->setHasCancel(HasCancel); return Dir; @@ -600,24 +538,16 @@ OMPParallelSectionsDirective * OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPParallelSectionsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPParallelSectionsDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1); } OMPTaskDirective * OMPTaskDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPTaskDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTaskDirective *Dir = - new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); Dir->setHasCancel(HasCancel); return Dir; } @@ -625,111 +555,79 @@ OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPTaskDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTaskDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); } OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc) { - void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); - OMPTaskyieldDirective *Dir = - new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); - return Dir; + return new (C) OMPTaskyieldDirective(StartLoc, EndLoc); } OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); - return new (Mem) OMPTaskyieldDirective(); + return new (C) OMPTaskyieldDirective(); } OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc) { - void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); - OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); - return Dir; + return new (C) OMPBarrierDirective(StartLoc, EndLoc); } OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); - return new (Mem) OMPBarrierDirective(); + return new (C) OMPBarrierDirective(); } OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc) { - void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); - OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); - return Dir; + return new (C) OMPTaskwaitDirective(StartLoc, EndLoc); } OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); - return new (Mem) OMPTaskwaitDirective(); + return new (C) OMPTaskwaitDirective(); } OMPTaskgroupDirective *OMPTaskgroupDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *ReductionRef) { - unsigned Size = llvm::alignTo(sizeof(OMPTaskgroupDirective) + - sizeof(OMPClause *) * Clauses.size(), - alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *) + sizeof(Expr *)); - OMPTaskgroupDirective *Dir = - new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc); Dir->setReductionRef(ReductionRef); - Dir->setClauses(Clauses); return Dir; } OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPTaskgroupDirective) + - sizeof(OMPClause *) * NumClauses, - alignof(Stmt *)); - void *Mem = C.Allocate(Size + sizeof(Stmt *) + sizeof(Expr *)); - return new (Mem) OMPTaskgroupDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1); } OMPCancellationPointDirective *OMPCancellationPointDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind CancelRegion) { - unsigned Size = - llvm::alignTo(sizeof(OMPCancellationPointDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size); - OMPCancellationPointDirective *Dir = - new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc); + auto *Dir = new (C) OMPCancellationPointDirective(StartLoc, EndLoc); Dir->setCancelRegion(CancelRegion); return Dir; } OMPCancellationPointDirective * OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPCancellationPointDirective), alignof(Stmt *)); - void *Mem = C.Allocate(Size); - return new (Mem) OMPCancellationPointDirective(); + return new (C) OMPCancellationPointDirective(); } OMPCancelDirective * OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, OpenMPDirectiveKind CancelRegion) { - unsigned Size = llvm::alignTo(sizeof(OMPCancelDirective) + - sizeof(OMPClause *) * Clauses.size(), - alignof(Stmt *)); - void *Mem = C.Allocate(Size); - OMPCancelDirective *Dir = - new (Mem) OMPCancelDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); + auto *Dir = createDirective( + C, Clauses, /*AssociatedStmt=*/nullptr, /*NumChildren=*/0, StartLoc, + EndLoc); Dir->setCancelRegion(CancelRegion); return Dir; } @@ -737,77 +635,52 @@ OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPCancelDirective) + - sizeof(OMPClause *) * NumClauses, - alignof(Stmt *)); - void *Mem = C.Allocate(Size); - return new (Mem) OMPCancelDirective(NumClauses); + return createEmptyDirective(C, NumClauses); } OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses) { - unsigned Size = - llvm::alignTo(sizeof(OMPFlushDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); - OMPFlushDirective *Dir = - new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - return Dir; + return createDirective( + C, Clauses, /*AssociatedStmt=*/nullptr, /*NumChildren=*/0, StartLoc, + EndLoc); } OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPFlushDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); - return new (Mem) OMPFlushDirective(NumClauses); + return createEmptyDirective(C, NumClauses); } OMPDepobjDirective *OMPDepobjDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses) { - unsigned Size = - llvm::alignTo(sizeof(OMPDepobjDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size(), - alignof(OMPDepobjDirective)); - auto *Dir = new (Mem) OMPDepobjDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - return Dir; + return createDirective( + C, Clauses, /*AssociatedStmt=*/nullptr, + /*NumChildren=*/0, StartLoc, EndLoc); } OMPDepobjDirective *OMPDepobjDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPDepobjDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses, - alignof(OMPDepobjDirective)); - return new (Mem) OMPDepobjDirective(NumClauses); + return createEmptyDirective(C, NumClauses); } OMPScanDirective *OMPScanDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses) { - unsigned Size = llvm::alignTo(sizeof(OMPScanDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size(), - alignof(OMPScanDirective)); - auto *Dir = new (Mem) OMPScanDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - return Dir; + return createDirective(C, Clauses, + /*AssociatedStmt=*/nullptr, + /*NumChildren=*/0, StartLoc, EndLoc); } OMPScanDirective *OMPScanDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPScanDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses, - alignof(OMPScanDirective)); - return new (Mem) OMPScanDirective(NumClauses); + return createEmptyDirective(C, NumClauses); } OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C, @@ -815,39 +688,25 @@ SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPOrderedDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(Stmt *) + sizeof(OMPClause *) * Clauses.size()); - OMPOrderedDirective *Dir = - new (Mem) OMPOrderedDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, cast_or_null(AssociatedStmt), + /*NumChildren=*/0, StartLoc, EndLoc); } OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, + bool IsStandalone, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPOrderedDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(Stmt *) + sizeof(OMPClause *) * NumClauses); - return new (Mem) OMPOrderedDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + !IsStandalone); } OMPAtomicDirective *OMPAtomicDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V, Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) { - unsigned Size = - llvm::alignTo(sizeof(OMPAtomicDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - 5 * sizeof(Stmt *)); - OMPAtomicDirective *Dir = - new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/4, StartLoc, EndLoc); Dir->setX(X); Dir->setV(V); Dir->setExpr(E); @@ -860,11 +719,8 @@ OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPAtomicDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *)); - return new (Mem) OMPAtomicDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/4); } OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C, @@ -872,39 +728,23 @@ SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetDirective *Dir = - new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); } OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTargetDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); } OMPTargetParallelDirective *OMPTargetParallelDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetParallelDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetParallelDirective *Dir = - new (Mem) OMPTargetParallelDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc); Dir->setTaskReductionRefExpr(TaskRedRef); Dir->setHasCancel(HasCancel); return Dir; @@ -913,26 +753,18 @@ OMPTargetParallelDirective * OMPTargetParallelDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetParallelDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTargetParallelDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1); } OMPTargetParallelForDirective *OMPTargetParallelForDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for)); - OMPTargetParallelForDirective *Dir = new (Mem) OMPTargetParallelForDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_parallel_for) + 1, StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -966,78 +798,52 @@ OMPTargetParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for)); - return new (Mem) OMPTargetParallelForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_parallel_for) + 1, + CollapsedNum); } OMPTargetDataDirective *OMPTargetDataDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetDataDirective *Dir = - new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); } OMPTargetDataDirective *OMPTargetDataDirective::CreateEmpty(const ASTContext &C, unsigned N, EmptyShell) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * N + sizeof(Stmt *)); - return new (Mem) OMPTargetDataDirective(N); + return createEmptyDirective( + C, N, /*HasAssociatedStmt=*/true); } OMPTargetEnterDataDirective *OMPTargetEnterDataDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetEnterDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetEnterDataDirective *Dir = - new (Mem) OMPTargetEnterDataDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); } OMPTargetEnterDataDirective * OMPTargetEnterDataDirective::CreateEmpty(const ASTContext &C, unsigned N, EmptyShell) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetEnterDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * N + sizeof(Stmt *)); - return new (Mem) OMPTargetEnterDataDirective(N); + return createEmptyDirective( + C, N, /*HasAssociatedStmt=*/true); } OMPTargetExitDataDirective *OMPTargetExitDataDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetExitDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetExitDataDirective *Dir = - new (Mem) OMPTargetExitDataDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); } OMPTargetExitDataDirective * OMPTargetExitDataDirective::CreateEmpty(const ASTContext &C, unsigned N, EmptyShell) { - void *Mem = C.Allocate( - llvm::alignTo(sizeof(OMPTargetExitDataDirective), alignof(OMPClause *)) + - sizeof(OMPClause *) * N + sizeof(Stmt *)); - return new (Mem) OMPTargetExitDataDirective(N); + return createEmptyDirective( + C, N, /*HasAssociatedStmt=*/true); } OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, @@ -1045,40 +851,24 @@ SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPTeamsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTeamsDirective *Dir = - new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective( + C, Clauses, AssociatedStmt, /*NumChildren=*/0, StartLoc, EndLoc); } OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTeamsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTeamsDirective(NumClauses); + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); } OMPTaskLoopDirective *OMPTaskLoopDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPTaskLoopDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop)); - OMPTaskLoopDirective *Dir = new (Mem) - OMPTaskLoopDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_taskloop), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1111,27 +901,19 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTaskLoopDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop)); - return new (Mem) OMPTaskLoopDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_taskloop), CollapsedNum); } OMPTaskLoopSimdDirective *OMPTaskLoopSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPTaskLoopSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_taskloop_simd)); - OMPTaskLoopSimdDirective *Dir = new (Mem) - OMPTaskLoopSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_taskloop_simd), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1162,27 +944,19 @@ OMPTaskLoopSimdDirective * OMPTaskLoopSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTaskLoopSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_taskloop_simd)); - return new (Mem) OMPTaskLoopSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_taskloop_simd), CollapsedNum); } OMPMasterTaskLoopDirective *OMPMasterTaskLoopDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel) { - unsigned Size = - llvm::alignTo(sizeof(OMPMasterTaskLoopDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_master_taskloop)); - OMPMasterTaskLoopDirective *Dir = new (Mem) OMPMasterTaskLoopDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_master_taskloop), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1215,28 +989,19 @@ OMPMasterTaskLoopDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPMasterTaskLoopDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_master_taskloop)); - return new (Mem) OMPMasterTaskLoopDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_master_taskloop), CollapsedNum); } OMPMasterTaskLoopSimdDirective *OMPMasterTaskLoopSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPMasterTaskLoopSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_master_taskloop_simd)); - auto *Dir = new (Mem) OMPMasterTaskLoopSimdDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_master_taskloop_simd), StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1268,29 +1033,19 @@ OMPMasterTaskLoopSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPMasterTaskLoopSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_master_taskloop_simd)); - return new (Mem) OMPMasterTaskLoopSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_master_taskloop_simd), CollapsedNum); } OMPParallelMasterTaskLoopDirective *OMPParallelMasterTaskLoopDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPParallelMasterTaskLoopDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop)); - auto *Dir = new (Mem) OMPParallelMasterTaskLoopDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop), StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1324,13 +1079,10 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPParallelMasterTaskLoopDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop)); - return new (Mem) OMPParallelMasterTaskLoopDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop), + CollapsedNum); } OMPParallelMasterTaskLoopSimdDirective * @@ -1338,16 +1090,10 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPParallelMasterTaskLoopSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop_simd)); - auto *Dir = new (Mem) OMPParallelMasterTaskLoopSimdDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1380,29 +1126,20 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPParallelMasterTaskLoopSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop_simd)); - return new (Mem) - OMPParallelMasterTaskLoopSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_parallel_master_taskloop_simd), + CollapsedNum); } OMPDistributeDirective *OMPDistributeDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPDistributeDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute)); - OMPDistributeDirective *Dir = new (Mem) - OMPDistributeDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_distribute), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1433,53 +1170,34 @@ OMPDistributeDirective * OMPDistributeDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPDistributeDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute)); - return new (Mem) OMPDistributeDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_distribute), CollapsedNum); } OMPTargetUpdateDirective *OMPTargetUpdateDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetUpdateDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetUpdateDirective *Dir = - new (Mem) OMPTargetUpdateDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/0, StartLoc, + EndLoc); } OMPTargetUpdateDirective * OMPTargetUpdateDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetUpdateDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTargetUpdateDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true); } OMPDistributeParallelForDirective *OMPDistributeParallelForDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - unsigned Size = llvm::alignTo(sizeof(OMPDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for)); - OMPDistributeParallelForDirective *Dir = - new (Mem) OMPDistributeParallelForDirective(StartLoc, EndLoc, - CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for) + 1, StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1527,13 +1245,10 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for)); - return new (Mem) OMPDistributeParallelForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for) + 1, + CollapsedNum); } OMPDistributeParallelForSimdDirective * @@ -1541,17 +1256,10 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for_simd)); - OMPDistributeParallelForSimdDirective *Dir = new (Mem) - OMPDistributeParallelForSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1597,30 +1305,20 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for_simd)); - return new (Mem) - OMPDistributeParallelForSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for_simd), + CollapsedNum); } OMPDistributeSimdDirective *OMPDistributeSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPDistributeSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_simd)); - OMPDistributeSimdDirective *Dir = new (Mem) OMPDistributeSimdDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_distribute_simd), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1652,30 +1350,19 @@ OMPDistributeSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPDistributeSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_distribute_simd)); - return new (Mem) OMPDistributeSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_distribute_simd), CollapsedNum); } OMPTargetParallelForSimdDirective *OMPTargetParallelForSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_parallel_for_simd)); - OMPTargetParallelForSimdDirective *Dir = - new (Mem) OMPTargetParallelForSimdDirective(StartLoc, EndLoc, - CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_parallel_for_simd), StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1708,13 +1395,10 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_parallel_for_simd)); - return new (Mem) OMPTargetParallelForSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_parallel_for_simd), + CollapsedNum); } OMPTargetSimdDirective * @@ -1722,15 +1406,10 @@ SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_simd)); - OMPTargetSimdDirective *Dir = new (Mem) - OMPTargetSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_simd), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1753,27 +1432,19 @@ OMPTargetSimdDirective * OMPTargetSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTargetSimdDirective), alignof(OMPClause *)); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_simd)); - return new (Mem) OMPTargetSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_simd), CollapsedNum); } OMPTeamsDistributeDirective *OMPTeamsDistributeDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = - llvm::alignTo(sizeof(OMPTeamsDistributeDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute)); - OMPTeamsDistributeDirective *Dir = new (Mem) OMPTeamsDistributeDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_teams_distribute), StartLoc, EndLoc, + CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1805,29 +1476,19 @@ OMPTeamsDistributeDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = - llvm::alignTo(sizeof(OMPTeamsDistributeDirective), alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute)); - return new (Mem) OMPTeamsDistributeDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_teams_distribute), CollapsedNum); } OMPTeamsDistributeSimdDirective *OMPTeamsDistributeSimdDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - unsigned Size = llvm::alignTo(sizeof(OMPTeamsDistributeSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_teams_distribute_simd)); - OMPTeamsDistributeSimdDirective *Dir = - new (Mem) OMPTeamsDistributeSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_simd), StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1858,13 +1519,9 @@ OMPTeamsDistributeSimdDirective *OMPTeamsDistributeSimdDirective::CreateEmpty( const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - unsigned Size = llvm::alignTo(sizeof(OMPTeamsDistributeSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_teams_distribute_simd)); - return new (Mem) OMPTeamsDistributeSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_simd), CollapsedNum); } OMPTeamsDistributeParallelForSimdDirective * @@ -1872,18 +1529,10 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - auto Size = llvm::alignTo(sizeof(OMPTeamsDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_teams_distribute_parallel_for_simd)); - OMPTeamsDistributeParallelForSimdDirective *Dir = new (Mem) - OMPTeamsDistributeParallelForSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -1929,15 +1578,10 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = llvm::alignTo(sizeof(OMPTeamsDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_teams_distribute_parallel_for_simd)); - return new (Mem) - OMPTeamsDistributeParallelForSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for_simd), + CollapsedNum); } OMPTeamsDistributeParallelForDirective * @@ -1945,17 +1589,10 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - auto Size = llvm::alignTo(sizeof(OMPTeamsDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for)); - OMPTeamsDistributeParallelForDirective *Dir = new (Mem) - OMPTeamsDistributeParallelForDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for) + 1, + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -2003,55 +1640,35 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = llvm::alignTo(sizeof(OMPTeamsDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for)); - return new (Mem) - OMPTeamsDistributeParallelForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for) + 1, + CollapsedNum); } OMPTargetTeamsDirective *OMPTargetTeamsDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetTeamsDirective *Dir = - new (Mem) OMPTargetTeamsDirective(StartLoc, EndLoc, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); - return Dir; + return createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/0, StartLoc, + EndLoc); } OMPTargetTeamsDirective * OMPTargetTeamsDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDirective), alignof(OMPClause *)); - void *Mem = - C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); - return new (Mem) OMPTargetTeamsDirective(NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true); } OMPTargetTeamsDistributeDirective *OMPTargetTeamsDistributeDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - auto Size = llvm::alignTo(sizeof(OMPTargetTeamsDistributeDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_teams_distribute)); - OMPTargetTeamsDistributeDirective *Dir = - new (Mem) OMPTargetTeamsDistributeDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute), StartLoc, + EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -2084,13 +1701,10 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = llvm::alignTo(sizeof(OMPTargetTeamsDistributeDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_teams_distribute)); - return new (Mem) OMPTargetTeamsDistributeDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute), + CollapsedNum); } OMPTargetTeamsDistributeParallelForDirective * @@ -2098,19 +1712,11 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_target_teams_distribute_parallel_for)); - OMPTargetTeamsDistributeParallelForDirective *Dir = - new (Mem) OMPTargetTeamsDistributeParallelForDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_parallel_for) + + 1, + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -2158,16 +1764,11 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDistributeParallelForDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_target_teams_distribute_parallel_for)); - return new (Mem) - OMPTargetTeamsDistributeParallelForDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_parallel_for) + + 1, + CollapsedNum); } OMPTargetTeamsDistributeParallelForSimdDirective * @@ -2175,19 +1776,11 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_target_teams_distribute_parallel_for_simd)); - OMPTargetTeamsDistributeParallelForSimdDirective *Dir = - new (Mem) OMPTargetTeamsDistributeParallelForSimdDirective( - StartLoc, EndLoc, CollapsedNum, Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, + OMPD_target_teams_distribute_parallel_for_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -2232,16 +1825,11 @@ OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty( const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = - llvm::alignTo(sizeof(OMPTargetTeamsDistributeParallelForSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, - OMPD_target_teams_distribute_parallel_for_simd)); - return new (Mem) OMPTargetTeamsDistributeParallelForSimdDirective( - CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, + OMPD_target_teams_distribute_parallel_for_simd), + CollapsedNum); } OMPTargetTeamsDistributeSimdDirective * @@ -2249,17 +1837,10 @@ const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs) { - auto Size = llvm::alignTo(sizeof(OMPTargetTeamsDistributeSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * Clauses.size() + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_simd)); - OMPTargetTeamsDistributeSimdDirective *Dir = new (Mem) - OMPTargetTeamsDistributeSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); - Dir->setClauses(Clauses); - Dir->setAssociatedStmt(AssociatedStmt); + auto *Dir = createDirective( + C, Clauses, AssociatedStmt, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_simd), + StartLoc, EndLoc, CollapsedNum); Dir->setIterationVariable(Exprs.IterationVarRef); Dir->setLastIteration(Exprs.LastIteration); Dir->setCalcLastIteration(Exprs.CalcLastIteration); @@ -2292,12 +1873,8 @@ unsigned NumClauses, unsigned CollapsedNum, EmptyShell) { - auto Size = llvm::alignTo(sizeof(OMPTargetTeamsDistributeSimdDirective), - alignof(OMPClause *)); - void *Mem = C.Allocate( - Size + sizeof(OMPClause *) * NumClauses + - sizeof(Stmt *) * - numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_simd)); - return new (Mem) - OMPTargetTeamsDistributeSimdDirective(CollapsedNum, NumClauses); + return createEmptyDirective( + C, NumClauses, /*HasAssociatedStmt=*/true, + numLoopChildren(CollapsedNum, OMPD_target_teams_distribute_simd), + CollapsedNum); } diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -4768,7 +4768,7 @@ void CodeGenFunction::EmitOMPOrderedDirective(const OMPOrderedDirective &S) { if (S.hasClausesOfKind()) { - assert(!S.getAssociatedStmt() && + assert(!S.hasAssociatedStmt() && "No associated statement must be in ordered depend construct."); for (const auto *DC : S.getClausesOfKind()) CGM.getOpenMPRuntime().emitDoacrossOrdered(*this, DC); diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -2253,100 +2253,39 @@ // OpenMP Directives. //===----------------------------------------------------------------------===// +static void readOMPChildren(ASTRecordReader &Record, OMPChildren *Data) { + SmallVector Clauses(Data->getNumClauses()); + for (unsigned I = 0, E = Data->getNumClauses(); I < E; ++I) + Clauses[I] = Record.readOMPClause(); + Data->setClauses(Clauses); + if (Data->hasAssociatedStmt()) + Data->setAssociatedStmt(Record.readSubStmt()); + for (unsigned I = 0, E = Data->getNumChildren(); I < E; ++I) + Data->getChildren()[I] = Record.readSubStmt(); +} + void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { + if (E->Data) { + // Skip NumClauses, NumChildren and HasAssociatedStmt fields. + Record.skipInts(3); + } E->setLocStart(readSourceLocation()); E->setLocEnd(readSourceLocation()); - SmallVector Clauses; - for (unsigned i = 0; i < E->getNumClauses(); ++i) - Clauses.push_back(Record.readOMPClause()); - E->setClauses(Clauses); - if (E->hasAssociatedStmt()) - E->setAssociatedStmt(Record.readSubStmt()); + if (OMPChildren *Data = E->Data) + readOMPChildren(Record, Data); } void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) { VisitStmt(D); - // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. - Record.skipInts(2); + // Field CollapsedNum was read in ReadStmtFromStream. + Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setIterationVariable(Record.readSubExpr()); - D->setLastIteration(Record.readSubExpr()); - D->setCalcLastIteration(Record.readSubExpr()); - D->setPreCond(Record.readSubExpr()); - D->setCond(Record.readSubExpr()); - D->setInit(Record.readSubExpr()); - D->setInc(Record.readSubExpr()); - D->setPreInits(Record.readSubStmt()); - if (isOpenMPWorksharingDirective(D->getDirectiveKind()) || - isOpenMPTaskLoopDirective(D->getDirectiveKind()) || - isOpenMPDistributeDirective(D->getDirectiveKind())) { - D->setIsLastIterVariable(Record.readSubExpr()); - D->setLowerBoundVariable(Record.readSubExpr()); - D->setUpperBoundVariable(Record.readSubExpr()); - D->setStrideVariable(Record.readSubExpr()); - D->setEnsureUpperBound(Record.readSubExpr()); - D->setNextLowerBound(Record.readSubExpr()); - D->setNextUpperBound(Record.readSubExpr()); - D->setNumIterations(Record.readSubExpr()); - } - if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) { - D->setPrevLowerBoundVariable(Record.readSubExpr()); - D->setPrevUpperBoundVariable(Record.readSubExpr()); - D->setDistInc(Record.readSubExpr()); - D->setPrevEnsureUpperBound(Record.readSubExpr()); - D->setCombinedLowerBoundVariable(Record.readSubExpr()); - D->setCombinedUpperBoundVariable(Record.readSubExpr()); - D->setCombinedEnsureUpperBound(Record.readSubExpr()); - D->setCombinedInit(Record.readSubExpr()); - D->setCombinedCond(Record.readSubExpr()); - D->setCombinedNextLowerBound(Record.readSubExpr()); - D->setCombinedNextUpperBound(Record.readSubExpr()); - D->setCombinedDistCond(Record.readSubExpr()); - D->setCombinedParForInDistCond(Record.readSubExpr()); - } - SmallVector Sub; - unsigned CollapsedNum = D->getCollapsedNumber(); - Sub.reserve(CollapsedNum); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setCounters(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setPrivateCounters(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setInits(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setUpdates(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setFinals(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setDependentCounters(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setDependentInits(Sub); - Sub.clear(); - for (unsigned i = 0; i < CollapsedNum; ++i) - Sub.push_back(Record.readSubExpr()); - D->setFinalsConditions(Sub); } void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) { @@ -2355,8 +2294,7 @@ void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) { @@ -2365,23 +2303,18 @@ void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } @@ -2392,16 +2325,13 @@ void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); D->DirName = Record.readDeclarationNameInfo(); } void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPParallelForSimdDirective( @@ -2412,28 +2342,20 @@ void ASTStmtReader::VisitOMPParallelMasterDirective( OMPParallelMasterDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); } void ASTStmtReader::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) { @@ -2453,100 +2375,73 @@ void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setReductionRef(Record.readSubExpr()); } void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPDepobjDirective(OMPDepobjDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPScanDirective(OMPScanDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setX(Record.readSubExpr()); - D->setV(Record.readSubExpr()); - D->setExpr(Record.readSubExpr()); - D->setUpdateExpr(Record.readSubExpr()); - D->IsXLHSInRHSPart = Record.readInt() != 0; - D->IsPostfixUpdate = Record.readInt() != 0; + D->IsXLHSInRHSPart = Record.readBool(); + D->IsPostfixUpdate = Record.readBool(); } void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) { VisitStmt(D); - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPTargetEnterDataDirective( OMPTargetEnterDataDirective *D) { VisitStmt(D); - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPTargetExitDataDirective( OMPTargetExitDataDirective *D) { VisitStmt(D); - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPTargetParallelDirective( OMPTargetParallelDirective *D) { VisitStmt(D); - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTargetParallelForDirective( OMPTargetParallelForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } @@ -2554,20 +2449,18 @@ OMPCancellationPointDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); - D->setCancelRegion(static_cast(Record.readInt())); + D->setCancelRegion(Record.readEnum()); } void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); - D->setCancelRegion(static_cast(Record.readInt())); + D->setCancelRegion(Record.readEnum()); } void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { VisitOMPLoopDirective(D); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) { @@ -2577,7 +2470,7 @@ void ASTStmtReader::VisitOMPMasterTaskLoopDirective( OMPMasterTaskLoopDirective *D) { VisitOMPLoopDirective(D); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPMasterTaskLoopSimdDirective( @@ -2588,7 +2481,7 @@ void ASTStmtReader::VisitOMPParallelMasterTaskLoopDirective( OMPParallelMasterTaskLoopDirective *D) { VisitOMPLoopDirective(D); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPParallelMasterTaskLoopSimdDirective( @@ -2602,15 +2495,13 @@ void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) { VisitStmt(D); - Record.skipInts(1); VisitOMPExecutableDirective(D); } void ASTStmtReader::VisitOMPDistributeParallelForDirective( OMPDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPDistributeParallelForSimdDirective( @@ -2650,14 +2541,11 @@ void ASTStmtReader::VisitOMPTeamsDistributeParallelForDirective( OMPTeamsDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) { VisitStmt(D); - // The NumClauses field was read in ReadStmtFromStream. - Record.skipInts(1); VisitOMPExecutableDirective(D); } @@ -2669,8 +2557,7 @@ void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForDirective( OMPTargetTeamsDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - D->setTaskReductionRefExpr(Record.readSubExpr()); - D->setHasCancel(Record.readInt()); + D->setHasCancel(Record.readBool()); } void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForSimdDirective( @@ -3242,24 +3129,24 @@ break; case STMT_OMP_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_FOR_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_FOR_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; @@ -3289,16 +3176,16 @@ break; case STMT_OMP_PARALLEL_FOR_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPParallelForDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; @@ -3351,10 +3238,13 @@ Context, Record[ASTStmtReader::NumStmtFields], Empty); break; - case STMT_OMP_ORDERED_DIRECTIVE: - S = OMPOrderedDirective::CreateEmpty( - Context, Record[ASTStmtReader::NumStmtFields], Empty); + case STMT_OMP_ORDERED_DIRECTIVE: { + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; + bool HasAssociatedStmt = Record[ASTStmtReader::NumStmtFields + 2]; + S = OMPOrderedDirective::CreateEmpty(Context, NumClauses, + !HasAssociatedStmt, Empty); break; + } case STMT_OMP_ATOMIC_DIRECTIVE: S = OMPAtomicDirective::CreateEmpty( @@ -3387,8 +3277,8 @@ break; case STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetParallelForDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; @@ -3414,72 +3304,72 @@ break; case STMT_OMP_TASKLOOP_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_MASTER_TASKLOOP_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPMasterTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPMasterTaskLoopSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPParallelMasterTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPParallelMasterTaskLoopSimdDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_DISTRIBUTE_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPDistributeParallelForDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPDistributeParallelForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); @@ -3487,56 +3377,56 @@ } case STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPDistributeSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetParallelForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TARGET_SIMD_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; - S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses, - CollapsedNum, Empty); - break; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; + S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses, + CollapsedNum, Empty); + break; } case STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: { - unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; - unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTeamsDistributeSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTeamsDistributeParallelForSimdDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTeamsDistributeParallelForDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; @@ -3548,32 +3438,32 @@ break; case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetTeamsDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetTeamsDistributeParallelForDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; } case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: { - auto NumClauses = Record[ASTStmtReader::NumStmtFields]; - auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields]; + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1]; S = OMPTargetTeamsDistributeSimdDirective::CreateEmpty( Context, NumClauses, CollapsedNum, Empty); break; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -2153,85 +2153,38 @@ //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// + +static void writeOMPChildren(ASTRecordWriter &Record, OMPChildren *Data) { + for (unsigned I = 0, E = Data->getNumClauses(); I < E; ++I) + Record.writeOMPClause(Data->getClauses()[I]); + if (Data->hasAssociatedStmt()) + Record.AddStmt(Data->getAssociatedStmt()); + for (unsigned I = 0, E = Data->getNumChildren(); I < E; ++I) + Record.AddStmt(Data->getChildren()[I]); +} + void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { + if (OMPChildren *Data = E->Data) { + Record.writeUInt32(Data->getNumClauses()); + Record.writeUInt32(Data->getNumChildren()); + Record.writeBool(Data->hasAssociatedStmt()); + } Record.AddSourceLocation(E->getBeginLoc()); Record.AddSourceLocation(E->getEndLoc()); - for (unsigned i = 0; i < E->getNumClauses(); ++i) { - Record.writeOMPClause(E->getClause(i)); - } - if (E->hasAssociatedStmt()) - Record.AddStmt(E->getAssociatedStmt()); + if (OMPChildren *Data = E->Data) + writeOMPChildren(Record, Data); } void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); - Record.push_back(D->getCollapsedNumber()); + Record.writeUInt32(D->getCollapsedNumber()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getIterationVariable()); - Record.AddStmt(D->getLastIteration()); - Record.AddStmt(D->getCalcLastIteration()); - Record.AddStmt(D->getPreCond()); - Record.AddStmt(D->getCond()); - Record.AddStmt(D->getInit()); - Record.AddStmt(D->getInc()); - Record.AddStmt(D->getPreInits()); - if (isOpenMPWorksharingDirective(D->getDirectiveKind()) || - isOpenMPTaskLoopDirective(D->getDirectiveKind()) || - isOpenMPDistributeDirective(D->getDirectiveKind())) { - Record.AddStmt(D->getIsLastIterVariable()); - Record.AddStmt(D->getLowerBoundVariable()); - Record.AddStmt(D->getUpperBoundVariable()); - Record.AddStmt(D->getStrideVariable()); - Record.AddStmt(D->getEnsureUpperBound()); - Record.AddStmt(D->getNextLowerBound()); - Record.AddStmt(D->getNextUpperBound()); - Record.AddStmt(D->getNumIterations()); - } - if (isOpenMPLoopBoundSharingDirective(D->getDirectiveKind())) { - Record.AddStmt(D->getPrevLowerBoundVariable()); - Record.AddStmt(D->getPrevUpperBoundVariable()); - Record.AddStmt(D->getDistInc()); - Record.AddStmt(D->getPrevEnsureUpperBound()); - Record.AddStmt(D->getCombinedLowerBoundVariable()); - Record.AddStmt(D->getCombinedUpperBoundVariable()); - Record.AddStmt(D->getCombinedEnsureUpperBound()); - Record.AddStmt(D->getCombinedInit()); - Record.AddStmt(D->getCombinedCond()); - Record.AddStmt(D->getCombinedNextLowerBound()); - Record.AddStmt(D->getCombinedNextUpperBound()); - Record.AddStmt(D->getCombinedDistCond()); - Record.AddStmt(D->getCombinedParForInDistCond()); - } - for (auto I : D->counters()) { - Record.AddStmt(I); - } - for (auto I : D->private_counters()) { - Record.AddStmt(I); - } - for (auto I : D->inits()) { - Record.AddStmt(I); - } - for (auto I : D->updates()) { - Record.AddStmt(I); - } - for (auto I : D->finals()) { - Record.AddStmt(I); - } - for (Stmt *S : D->dependent_counters()) - Record.AddStmt(S); - for (Stmt *S : D->dependent_inits()) - Record.AddStmt(S); - for (Stmt *S : D->finals_conditions()) - Record.AddStmt(S); } void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; } @@ -2242,8 +2195,7 @@ void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_FOR_DIRECTIVE; } @@ -2254,23 +2206,20 @@ void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE; } void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_SECTION_DIRECTIVE; } void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_SINGLE_DIRECTIVE; } @@ -2283,7 +2232,6 @@ void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Record.AddDeclarationNameInfo(D->getDirectiveName()); Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE; @@ -2291,8 +2239,7 @@ void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE; } @@ -2305,53 +2252,41 @@ void ASTStmtWriter::VisitOMPParallelMasterDirective( OMPParallelMasterDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE; } void ASTStmtWriter::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE; } void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TASK_DIRECTIVE; } void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getX()); - Record.AddStmt(D->getV()); - Record.AddStmt(D->getExpr()); - Record.AddStmt(D->getUpdateExpr()); - Record.push_back(D->isXLHSInRHSPart() ? 1 : 0); - Record.push_back(D->isPostfixUpdate() ? 1 : 0); + Record.writeBool(D->isXLHSInRHSPart()); + Record.writeBool(D->isPostfixUpdate()); Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE; } void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_DIRECTIVE; } void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE; } @@ -2359,7 +2294,6 @@ void ASTStmtWriter::VisitOMPTargetEnterDataDirective( OMPTargetEnterDataDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE; } @@ -2367,7 +2301,6 @@ void ASTStmtWriter::VisitOMPTargetExitDataDirective( OMPTargetExitDataDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE; } @@ -2375,9 +2308,7 @@ void ASTStmtWriter::VisitOMPTargetParallelDirective( OMPTargetParallelDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE; } @@ -2385,8 +2316,7 @@ void ASTStmtWriter::VisitOMPTargetParallelForDirective( OMPTargetParallelForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE; } @@ -2410,43 +2340,36 @@ void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.AddStmt(D->getReductionRef()); Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE; } void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_FLUSH_DIRECTIVE; } void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE; } void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_SCAN_DIRECTIVE; } void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_ORDERED_DIRECTIVE; } void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TEAMS_DIRECTIVE; } @@ -2455,21 +2378,20 @@ OMPCancellationPointDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); - Record.push_back(uint64_t(D->getCancelRegion())); + Record.writeEnum(D->getCancelRegion()); Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE; } void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); - Record.push_back(uint64_t(D->getCancelRegion())); + Record.writeEnum(D->getCancelRegion()); Code = serialization::STMT_OMP_CANCEL_DIRECTIVE; } void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { VisitOMPLoopDirective(D); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE; } @@ -2481,7 +2403,7 @@ void ASTStmtWriter::VisitOMPMasterTaskLoopDirective( OMPMasterTaskLoopDirective *D) { VisitOMPLoopDirective(D); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE; } @@ -2494,7 +2416,7 @@ void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective( OMPParallelMasterTaskLoopDirective *D) { VisitOMPLoopDirective(D); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE; } @@ -2511,7 +2433,6 @@ void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE; } @@ -2519,8 +2440,7 @@ void ASTStmtWriter::VisitOMPDistributeParallelForDirective( OMPDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; } @@ -2568,14 +2488,12 @@ void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective( OMPTeamsDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; } void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) { VisitStmt(D); - Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE; } @@ -2589,8 +2507,7 @@ void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective( OMPTargetTeamsDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); - Record.AddStmt(D->getTaskReductionRefExpr()); - Record.push_back(D->hasCancel() ? 1 : 0); + Record.writeBool(D->hasCancel()); Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE; } diff --git a/clang/test/AST/ast-dump-openmp-ordered.c b/clang/test/AST/ast-dump-openmp-ordered.c --- a/clang/test/AST/ast-dump-openmp-ordered.c +++ b/clang/test/AST/ast-dump-openmp-ordered.c @@ -74,8 +74,7 @@ // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | `-CompoundStmt {{.*}} // CHECK-NEXT: | | `-OMPOrderedDirective {{.*}} openmp_standalone_directive -// CHECK-NEXT: | | |-OMPDependClause {{.*}} > -// CHECK-NEXT: | | `-<<>> +// CHECK-NEXT: | | `-OMPDependClause {{.*}} > // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-ordered.c:15:1) *const restrict' // CHECK-NEXT: | `-VarDecl {{.*}} col:12 used i 'int' cinit // CHECK-NEXT: | `-IntegerLiteral {{.*}} 'int' 0