From: James Y Knight Date: Fri, 1 Jan 2016 00:38:24 +0000 (+0000) Subject: [TrailingObjects] Convert classes in OpenMPClause.h X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb8772dd106fb9b9cb0737575c15652bace0b9c7;p=clang [TrailingObjects] Convert classes in OpenMPClause.h git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256683 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index bb982f3acf..56548ebb98 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -84,21 +84,15 @@ protected: /// \brief Fetches list of variables associated with this clause. MutableArrayRef getVarRefs() { return MutableArrayRef( - reinterpret_cast( - reinterpret_cast(this) + - llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf())), - NumVars); + static_cast(this)->template getTrailingObjects(), NumVars); } /// \brief Sets the list of variables for this clause. void setVarRefs(ArrayRef VL) { assert(VL.size() == NumVars && "Number of variables is not the same as the preallocated buffer"); - std::copy( - VL.begin(), VL.end(), - reinterpret_cast( - reinterpret_cast(this) + - llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf()))); + std::copy(VL.begin(), VL.end(), + static_cast(this)->template getTrailingObjects()); } /// \brief Build a clause with \a N variables @@ -142,9 +136,7 @@ public: /// \brief Fetches list of all variables in the clause. ArrayRef getVarRefs() const { return llvm::makeArrayRef( - reinterpret_cast( - reinterpret_cast(this) + - llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf())), + static_cast(this)->template getTrailingObjects(), NumVars); } }; @@ -1160,7 +1152,11 @@ public: /// In this example directive '#pragma omp parallel' has clause 'private' /// with the variables 'a' and 'b'. /// -class OMPPrivateClause : public OMPVarListClause { +class OMPPrivateClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Build clause with number of variables \a N. /// @@ -1252,7 +1248,11 @@ public: /// In this example directive '#pragma omp parallel' has clause 'firstprivate' /// with the variables 'a' and 'b'. /// -class OMPFirstprivateClause : public OMPVarListClause { +class OMPFirstprivateClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Build clause with number of variables \a N. @@ -1372,7 +1372,9 @@ public: /// \endcode /// In this example directive '#pragma omp simd' has clause 'lastprivate' /// with the variables 'a' and 'b'. -class OMPLastprivateClause : public OMPVarListClause { +class OMPLastprivateClause final + : public OMPVarListClause, + private llvm::TrailingObjects { // There are 4 additional tail-allocated arrays at the end of the class: // 1. Contains list of pseudo variables with the default initialization for // each non-firstprivate variables. Used in codegen for initialization of @@ -1390,6 +1392,8 @@ class OMPLastprivateClause : public OMPVarListClause { // Required for proper codegen of final assignment performed by the // lastprivate clause. // + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Build clause with number of variables \a N. @@ -1557,7 +1561,11 @@ public: /// In this example directive '#pragma omp parallel' has clause 'shared' /// with the variables 'a' and 'b'. /// -class OMPSharedClause : public OMPVarListClause { +class OMPSharedClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; /// \brief Build clause with number of variables \a N. /// /// \param StartLoc Starting location of the clause. @@ -1617,7 +1625,11 @@ public: /// In this example directive '#pragma omp parallel' has clause 'reduction' /// with operator '+' and the variables 'a' and 'b'. /// -class OMPReductionClause : public OMPVarListClause { +class OMPReductionClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Location of ':'. SourceLocation ColonLoc; @@ -1819,7 +1831,11 @@ public: /// In this example directive '#pragma omp simd' has clause 'linear' /// with variables 'a', 'b' and linear step '2'. /// -class OMPLinearClause : public OMPVarListClause { +class OMPLinearClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Modifier of 'linear' clause. OpenMPLinearClauseKind Modifier; @@ -2039,7 +2055,11 @@ public: /// In this example directive '#pragma omp simd' has clause 'aligned' /// with variables 'a', 'b' and alignment '8'. /// -class OMPAlignedClause : public OMPVarListClause { +class OMPAlignedClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Location of ':'. SourceLocation ColonLoc; @@ -2123,7 +2143,9 @@ public: /// In this example directive '#pragma omp parallel' has clause 'copyin' /// with the variables 'a' and 'b'. /// -class OMPCopyinClause : public OMPVarListClause { +class OMPCopyinClause final + : public OMPVarListClause, + private llvm::TrailingObjects { // Class has 3 additional tail allocated arrays: // 1. List of helper expressions for proper generation of assignment operation // required for copyin clause. This list represents sources. @@ -2137,6 +2159,8 @@ class OMPCopyinClause : public OMPVarListClause { // threadprivate variables to local instances of that variables in other // implicit threads. + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Build clause with number of variables \a N. /// @@ -2282,7 +2306,11 @@ public: /// In this example directive '#pragma omp single' has clause 'copyprivate' /// with the variables 'a' and 'b'. /// -class OMPCopyprivateClause : public OMPVarListClause { +class OMPCopyprivateClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Build clause with number of variables \a N. /// @@ -2431,7 +2459,11 @@ public: /// In this example directive '#pragma omp flush' has implicit clause 'flush' /// with the variables 'a' and 'b'. /// -class OMPFlushClause : public OMPVarListClause { +class OMPFlushClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; /// \brief Build clause with number of variables \a N. /// /// \param StartLoc Starting location of the clause. @@ -2491,7 +2523,11 @@ public: /// In this example directive '#pragma omp task' with clause 'depend' with the /// variables 'a' and 'b' with dependency 'in'. /// -class OMPDependClause : public OMPVarListClause { +class OMPDependClause final + : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Dependency type (one of in, out, inout). OpenMPDependClauseKind DepKind; @@ -2695,7 +2731,10 @@ public: /// In this example directive '#pragma omp target' has clause 'map' /// with the variables 'a' and 'b'. /// -class OMPMapClause : public OMPVarListClause { +class OMPMapClause final : public OMPVarListClause, + private llvm::TrailingObjects { + friend TrailingObjects; + friend class OMPVarListClause; friend class OMPClauseReader; /// \brief Map type modifier for the 'map' clause. diff --git a/lib/AST/OpenMPClause.cpp b/lib/AST/OpenMPClause.cpp index cd60d3727b..1ef43f7694 100644 --- a/lib/AST/OpenMPClause.cpp +++ b/lib/AST/OpenMPClause.cpp @@ -40,9 +40,7 @@ OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL, ArrayRef PrivateVL) { // Allocate space for private variables and initializer expressions. - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), - llvm::alignOf()) + - 2 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(2 * VL.size())); OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -52,9 +50,7 @@ OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), - llvm::alignOf()) + - 2 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(2 * N)); return new (Mem) OMPPrivateClause(N); } @@ -75,9 +71,7 @@ OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL, ArrayRef PrivateVL, ArrayRef InitVL) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), - llvm::alignOf()) + - 3 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(3 * VL.size())); OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -88,9 +82,7 @@ OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), - llvm::alignOf()) + - 3 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(3 * N)); return new (Mem) OMPFirstprivateClause(N); } @@ -126,9 +118,7 @@ OMPLastprivateClause *OMPLastprivateClause::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL, ArrayRef SrcExprs, ArrayRef DstExprs, ArrayRef AssignmentOps) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), - llvm::alignOf()) + - 5 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size())); OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -140,9 +130,7 @@ OMPLastprivateClause *OMPLastprivateClause::Create( OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), - llvm::alignOf()) + - 5 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(5 * N)); return new (Mem) OMPLastprivateClause(N); } @@ -151,9 +139,7 @@ OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), - llvm::alignOf()) + - sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -161,9 +147,7 @@ OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, } OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), - llvm::alignOf()) + - sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(N)); return new (Mem) OMPSharedClause(N); } @@ -198,9 +182,7 @@ OMPLinearClause *OMPLinearClause::Create( ArrayRef PL, ArrayRef IL, Expr *Step, Expr *CalcStep) { // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions // (Step and CalcStep). - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), - llvm::alignOf()) + - (5 * VL.size() + 2) * sizeof(Expr *)); + void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size() + 2)); OMPLinearClause *Clause = new (Mem) OMPLinearClause( StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -221,9 +203,7 @@ OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, unsigned NumVars) { // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions // (Step and CalcStep). - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), - llvm::alignOf()) + - (5 * NumVars + 2) * sizeof(Expr *)); + void *Mem = C.Allocate(totalSizeToAlloc(5 * NumVars + 2)); return new (Mem) OMPLinearClause(NumVars); } @@ -231,9 +211,7 @@ OMPAlignedClause * OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef VL, Expr *A) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), - llvm::alignOf()) + - sizeof(Expr *) * (VL.size() + 1)); + void *Mem = C.Allocate(totalSizeToAlloc(VL.size() + 1)); OMPAlignedClause *Clause = new (Mem) OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -243,9 +221,7 @@ OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, unsigned NumVars) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), - llvm::alignOf()) + - sizeof(Expr *) * (NumVars + 1)); + void *Mem = C.Allocate(totalSizeToAlloc(NumVars + 1)); return new (Mem) OMPAlignedClause(NumVars); } @@ -275,9 +251,7 @@ OMPCopyinClause *OMPCopyinClause::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL, ArrayRef SrcExprs, ArrayRef DstExprs, ArrayRef AssignmentOps) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), - llvm::alignOf()) + - 4 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(4 * VL.size())); OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -288,9 +262,7 @@ OMPCopyinClause *OMPCopyinClause::Create( } OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), - llvm::alignOf()) + - 4 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(4 * N)); return new (Mem) OMPCopyinClause(N); } @@ -320,9 +292,7 @@ OMPCopyprivateClause *OMPCopyprivateClause::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL, ArrayRef SrcExprs, ArrayRef DstExprs, ArrayRef AssignmentOps) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), - llvm::alignOf()) + - 4 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(4 * VL.size())); OMPCopyprivateClause *Clause = new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -334,9 +304,7 @@ OMPCopyprivateClause *OMPCopyprivateClause::Create( OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), - llvm::alignOf()) + - 4 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(4 * N)); return new (Mem) OMPCopyprivateClause(N); } @@ -373,9 +341,7 @@ OMPReductionClause *OMPReductionClause::Create( NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, ArrayRef Privates, ArrayRef LHSExprs, ArrayRef RHSExprs, ArrayRef ReductionOps) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), - llvm::alignOf()) + - 5 * sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size())); OMPReductionClause *Clause = new (Mem) OMPReductionClause( StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); Clause->setVarRefs(VL); @@ -388,9 +354,7 @@ OMPReductionClause *OMPReductionClause::Create( OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), - llvm::alignOf()) + - 5 * sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(5 * N)); return new (Mem) OMPReductionClause(N); } @@ -399,9 +363,7 @@ OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef VL) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), - llvm::alignOf()) + - sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); OMPFlushClause *Clause = new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -409,9 +371,7 @@ OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, } OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), - llvm::alignOf()) + - sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(N)); return new (Mem) OMPFlushClause(N); } @@ -420,9 +380,7 @@ OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPDependClauseKind DepKind, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef VL) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), - llvm::alignOf()) + - sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); OMPDependClause *Clause = new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -433,9 +391,7 @@ OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, } OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), - llvm::alignOf()) + - sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(N)); return new (Mem) OMPDependClause(N); } @@ -445,9 +401,7 @@ OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type, SourceLocation TypeLoc) { - void *Mem = C.Allocate( - llvm::RoundUpToAlignment(sizeof(OMPMapClause), llvm::alignOf()) + - sizeof(Expr *) * VL.size()); + void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); OMPMapClause *Clause = new (Mem) OMPMapClause( TypeModifier, Type, TypeLoc, StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); @@ -458,8 +412,6 @@ OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, } OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned N) { - void *Mem = C.Allocate( - llvm::RoundUpToAlignment(sizeof(OMPMapClause), llvm::alignOf()) + - sizeof(Expr *) * N); + void *Mem = C.Allocate(totalSizeToAlloc(N)); return new (Mem) OMPMapClause(N); }