/// \brief This represents clauses with the list of variables like 'private',
/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
/// '#pragma omp ...' directives.
-template <class T> class OMPVarList {
+template <class T> class OMPVarListClause : public OMPClause {
friend class OMPClauseReader;
/// \brief Location of '('.
SourceLocation LParenLoc;
/// \brief Fetches list of variables associated with this clause.
llvm::MutableArrayRef<Expr *> getVarRefs() {
return llvm::MutableArrayRef<Expr *>(
- reinterpret_cast<Expr **>(static_cast<T *>(this) + 1), NumVars);
+ reinterpret_cast<Expr **>(
+ reinterpret_cast<char *>(this) +
+ llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
+ NumVars);
}
/// \brief Sets the list of variables for this clause.
void setVarRefs(ArrayRef<Expr *> VL) {
assert(VL.size() == NumVars &&
"Number of variables is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(),
- reinterpret_cast<Expr **>(static_cast<T *>(this) + 1));
+ std::copy(
+ VL.begin(), VL.end(),
+ reinterpret_cast<Expr **>(
+ reinterpret_cast<char *>(this) +
+ llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
}
/// \brief Build clause with number of variables \a N.
///
+ /// \param K Kind of the clause.
+ /// \param StartLoc Starting location of the clause (the clause keyword).
+ /// \param LParenLoc Location of '('.
+ /// \param EndLoc Ending location of the clause.
/// \param N Number of the variables in the clause.
///
- OMPVarList(SourceLocation LParenLoc, unsigned N)
- : LParenLoc(LParenLoc), NumVars(N) {}
+ OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
+ : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
public:
typedef llvm::MutableArrayRef<Expr *>::iterator varlist_iterator;
/// \brief Fetches list of all variables in the clause.
ArrayRef<const Expr *> getVarRefs() const {
return ArrayRef<const Expr *>(
- reinterpret_cast<const Expr *const *>(static_cast<const T *>(this) + 1),
+ reinterpret_cast<const Expr *const *>(
+ reinterpret_cast<const char *>(this) +
+ llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
NumVars);
}
};
/// In this example directive '#pragma omp parallel' has clause 'private'
/// with the variables 'a' and 'b'.
///
-class OMPPrivateClause : public OMPClause, public OMPVarList<OMPPrivateClause> {
+class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
/// \brief Build clause with number of variables \a N.
///
/// \param StartLoc Starting location of the clause.
///
OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, unsigned N)
- : OMPClause(OMPC_private, StartLoc, EndLoc),
- OMPVarList<OMPPrivateClause>(LParenLoc, N) {}
+ : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
+ EndLoc, N) {}
/// \brief Build an empty clause.
///
/// \param N Number of variables.
///
explicit OMPPrivateClause(unsigned N)
- : OMPClause(OMPC_private, SourceLocation(), SourceLocation()),
- OMPVarList<OMPPrivateClause>(SourceLocation(), N) {}
+ : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
+ SourceLocation(), SourceLocation(),
+ N) {}
public:
/// \brief Creates clause with a list of variables \a VL.
/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
/// with the variables 'a' and 'b'.
///
-class OMPFirstprivateClause : public OMPClause,
- public OMPVarList<OMPFirstprivateClause> {
+class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
/// \brief Build clause with number of variables \a N.
///
/// \param StartLoc Starting location of the clause.
///
OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, unsigned N)
- : OMPClause(OMPC_firstprivate, StartLoc, EndLoc),
- OMPVarList<OMPFirstprivateClause>(LParenLoc, N) {}
+ : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
+ LParenLoc, EndLoc, N) {}
/// \brief Build an empty clause.
///
/// \param N Number of variables.
///
explicit OMPFirstprivateClause(unsigned N)
- : OMPClause(OMPC_firstprivate, SourceLocation(), SourceLocation()),
- OMPVarList<OMPFirstprivateClause>(SourceLocation(), N) {}
+ : OMPVarListClause<OMPFirstprivateClause>(
+ OMPC_firstprivate, SourceLocation(), SourceLocation(),
+ SourceLocation(), N) {}
public:
/// \brief Creates clause with a list of variables \a VL.
/// In this example directive '#pragma omp parallel' has clause 'shared'
/// with the variables 'a' and 'b'.
///
-class OMPSharedClause : public OMPClause, public OMPVarList<OMPSharedClause> {
+class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
/// \brief Build clause with number of variables \a N.
///
/// \param StartLoc Starting location of the clause.
///
OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, unsigned N)
- : OMPClause(OMPC_shared, StartLoc, EndLoc),
- OMPVarList<OMPSharedClause>(LParenLoc, N) {}
+ : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
+ EndLoc, N) {}
/// \brief Build an empty clause.
///
/// \param N Number of variables.
///
explicit OMPSharedClause(unsigned N)
- : OMPClause(OMPC_shared, SourceLocation(), SourceLocation()),
- OMPVarList<OMPSharedClause>(SourceLocation(), N) {}
+ : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
+ SourceLocation(), SourceLocation(),
+ N) {}
public:
/// \brief Creates clause with a list of variables \a VL.
llvm::MutableArrayRef<OMPClause *> Clauses;
/// \brief Associated statement (if any) and expressions.
llvm::MutableArrayRef<Stmt *> StmtAndExpressions;
+
protected:
/// \brief Build instance of directive of class \a K.
///
OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K,
SourceLocation StartLoc, SourceLocation EndLoc,
unsigned NumClauses, unsigned NumberOfExpressions)
- : Stmt(SC), Kind(K), StartLoc(StartLoc), EndLoc(EndLoc),
- Clauses(reinterpret_cast<OMPClause **>(static_cast<T *>(this) + 1),
- NumClauses),
- StmtAndExpressions(reinterpret_cast<Stmt **>(Clauses.end()),
- NumberOfExpressions) { }
+ : Stmt(SC), Kind(K), StartLoc(StartLoc), EndLoc(EndLoc),
+ Clauses(reinterpret_cast<OMPClause **>(
+ reinterpret_cast<char *>(this) +
+ llvm::RoundUpToAlignment(sizeof(T),
+ llvm::alignOf<OMPClause *>())),
+ NumClauses),
+ StmtAndExpressions(reinterpret_cast<Stmt **>(Clauses.end()),
+ NumberOfExpressions) {}
/// \brief Sets the list of variables for this clause.
///
///
/// /param S Associated statement.
///
- void setAssociatedStmt(Stmt *S) {
- StmtAndExpressions[0] = S;
- }
+ void setAssociatedStmt(Stmt *S) { StmtAndExpressions[0] = S; }
public:
/// \brief Returns starting location of directive kind.
}
/// \brief Returns statement associated with the directive.
- Stmt *getAssociatedStmt() const {
- return StmtAndExpressions[0];
- }
+ Stmt *getAssociatedStmt() const { return StmtAndExpressions[0]; }
OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
///
OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc,
unsigned N)
- : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
- StartLoc, EndLoc, N, 1) { }
+ : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
+ StartLoc, EndLoc, N, 1) {}
/// \brief Build an empty directive.
///
/// \param N Number of clauses.
///
explicit OMPParallelDirective(unsigned N)
- : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
- SourceLocation(), SourceLocation(), N, 1) { }
+ : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
+ SourceLocation(), SourceLocation(), N, 1) {}
+
public:
/// \brief Creates directive with a list of \a Clauses.
///
/// \param Clauses List of clauses.
/// \param AssociatedStmt Statement associated with the directive.
///
- static OMPParallelDirective *Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation EndLoc,
- ArrayRef<OMPClause *> Clauses,
- Stmt *AssociatedStmt);
+ static OMPParallelDirective *
+ Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+ ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
/// \brief Creates an empty directive with the place for \a N clauses.
///
}
};
-} // end namespace clang
+} // end namespace clang
#endif
SourceLocation LParenLoc,
SourceLocation EndLoc,
ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * VL.size(),
- llvm::alignOf<OMPPrivateClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * VL.size());
OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc,
EndLoc, VL.size());
Clause->setVarRefs(VL);
OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
unsigned N) {
- void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * N,
- llvm::alignOf<OMPPrivateClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * N);
return new (Mem) OMPPrivateClause(N);
}
SourceLocation LParenLoc,
SourceLocation EndLoc,
ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) +
- sizeof(Expr *) * VL.size(),
- llvm::alignOf<OMPFirstprivateClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * VL.size());
OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc,
LParenLoc,
EndLoc,
OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
unsigned N) {
- void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) + sizeof(Expr *) * N,
- llvm::alignOf<OMPFirstprivateClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * N);
return new (Mem) OMPFirstprivateClause(N);
}
SourceLocation LParenLoc,
SourceLocation EndLoc,
ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * VL.size(),
- llvm::alignOf<OMPSharedClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * VL.size());
OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
EndLoc, VL.size());
Clause->setVarRefs(VL);
OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
unsigned N) {
- void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * N,
- llvm::alignOf<OMPSharedClause>());
+ void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
+ llvm::alignOf<Expr *>()) +
+ sizeof(Expr *) * N);
return new (Mem) OMPSharedClause(N);
}
SourceLocation EndLoc,
ArrayRef<OMPClause *> Clauses,
Stmt *AssociatedStmt) {
- void *Mem = C.Allocate(sizeof(OMPParallelDirective) +
- sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *),
- llvm::alignOf<OMPParallelDirective>());
+ unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
+ llvm::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);
OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
unsigned N,
EmptyShell) {
- void *Mem = C.Allocate(sizeof(OMPParallelDirective) +
- sizeof(OMPClause *) * N + sizeof(Stmt *),
- llvm::alignOf<OMPParallelDirective>());
+ unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
+ llvm::alignOf<OMPClause *>());
+ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * N + sizeof(Stmt *));
return new (Mem) OMPParallelDirective(N);
}