1 //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Stmt class and statement subclasses.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ASTDiagnostic.h"
16 #include "clang/AST/ExprCXX.h"
17 #include "clang/AST/ExprObjC.h"
18 #include "clang/AST/Stmt.h"
19 #include "clang/AST/StmtCXX.h"
20 #include "clang/AST/StmtObjC.h"
21 #include "clang/AST/StmtOpenMP.h"
22 #include "clang/AST/Type.h"
23 #include "clang/Basic/CharInfo.h"
24 #include "clang/Basic/TargetInfo.h"
25 #include "clang/Lex/Token.h"
26 #include "llvm/ADT/StringExtras.h"
27 #include "llvm/Support/raw_ostream.h"
28 using namespace clang;
30 static struct StmtClassNameTable {
34 } StmtClassInfo[Stmt::lastStmtConstant+1];
36 static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
37 static bool Initialized = false;
39 return StmtClassInfo[E];
41 // Intialize the table on the first use.
43 #define ABSTRACT_STMT(STMT)
44 #define STMT(CLASS, PARENT) \
45 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
47 #include "clang/AST/StmtNodes.inc"
49 return StmtClassInfo[E];
52 void *Stmt::operator new(size_t bytes, const ASTContext& C,
54 return ::operator new(bytes, C, alignment);
57 const char *Stmt::getStmtClassName() const {
58 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
61 void Stmt::PrintStats() {
62 // Ensure the table is primed.
63 getStmtInfoTableEntry(Stmt::NullStmtClass);
66 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
67 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
68 if (StmtClassInfo[i].Name == nullptr) continue;
69 sum += StmtClassInfo[i].Counter;
71 llvm::errs() << " " << sum << " stmts/exprs total.\n";
73 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
74 if (StmtClassInfo[i].Name == nullptr) continue;
75 if (StmtClassInfo[i].Counter == 0) continue;
76 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
77 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
78 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
80 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
83 llvm::errs() << "Total bytes = " << sum << "\n";
86 void Stmt::addStmtClass(StmtClass s) {
87 ++getStmtInfoTableEntry(s).Counter;
90 bool Stmt::StatisticsEnabled = false;
91 void Stmt::EnableStatistics() {
92 StatisticsEnabled = true;
95 Stmt *Stmt::IgnoreImplicit() {
98 if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
99 s = ewc->getSubExpr();
101 if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
102 s = mte->GetTemporaryExpr();
104 if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
105 s = bte->getSubExpr();
107 while (auto *ice = dyn_cast<ImplicitCastExpr>(s))
108 s = ice->getSubExpr();
113 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
114 /// stmt at the top, if \a IgnoreCaptured is true.
115 Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
118 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
119 S = CapS->getCapturedStmt();
121 if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
122 S = AS->getSubStmt();
123 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
133 /// \brief Strip off all label-like statements.
135 /// This will strip off label statements, case statements, attributed
136 /// statements and default statements recursively.
137 const Stmt *Stmt::stripLabelLikeStatements() const {
138 const Stmt *S = this;
140 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
141 S = LS->getSubStmt();
142 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
143 S = SC->getSubStmt();
144 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
145 S = AS->getSubStmt();
155 // These silly little functions have to be static inline to suppress
156 // unused warnings, and they have to be defined to suppress other
158 static inline good is_good(good) { return good(); }
160 typedef Stmt::child_range children_t();
161 template <class T> good implements_children(children_t T::*) {
164 LLVM_ATTRIBUTE_UNUSED
165 static inline bad implements_children(children_t Stmt::*) {
169 typedef SourceLocation getLocStart_t() const;
170 template <class T> good implements_getLocStart(getLocStart_t T::*) {
173 LLVM_ATTRIBUTE_UNUSED
174 static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
178 typedef SourceLocation getLocEnd_t() const;
179 template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
182 LLVM_ATTRIBUTE_UNUSED
183 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
187 #define ASSERT_IMPLEMENTS_children(type) \
188 (void) is_good(implements_children(&type::children))
189 #define ASSERT_IMPLEMENTS_getLocStart(type) \
190 (void) is_good(implements_getLocStart(&type::getLocStart))
191 #define ASSERT_IMPLEMENTS_getLocEnd(type) \
192 (void) is_good(implements_getLocEnd(&type::getLocEnd))
195 /// Check whether the various Stmt classes implement their member
197 LLVM_ATTRIBUTE_UNUSED
198 static inline void check_implementations() {
199 #define ABSTRACT_STMT(type)
200 #define STMT(type, base) \
201 ASSERT_IMPLEMENTS_children(type); \
202 ASSERT_IMPLEMENTS_getLocStart(type); \
203 ASSERT_IMPLEMENTS_getLocEnd(type);
204 #include "clang/AST/StmtNodes.inc"
207 Stmt::child_range Stmt::children() {
208 switch (getStmtClass()) {
209 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
210 #define ABSTRACT_STMT(type)
211 #define STMT(type, base) \
212 case Stmt::type##Class: \
213 return static_cast<type*>(this)->children();
214 #include "clang/AST/StmtNodes.inc"
216 llvm_unreachable("unknown statement kind!");
219 // Amusing macro metaprogramming hack: check whether a class provides
220 // a more specific implementation of getSourceRange.
222 // See also Expr.cpp:getExprLoc().
224 /// This implementation is used when a class provides a custom
225 /// implementation of getSourceRange.
226 template <class S, class T>
227 SourceRange getSourceRangeImpl(const Stmt *stmt,
228 SourceRange (T::*v)() const) {
229 return static_cast<const S*>(stmt)->getSourceRange();
232 /// This implementation is used when a class doesn't provide a custom
233 /// implementation of getSourceRange. Overload resolution should pick it over
234 /// the implementation above because it's more specialized according to
235 /// function template partial ordering.
237 SourceRange getSourceRangeImpl(const Stmt *stmt,
238 SourceRange (Stmt::*v)() const) {
239 return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
240 static_cast<const S*>(stmt)->getLocEnd());
244 SourceRange Stmt::getSourceRange() const {
245 switch (getStmtClass()) {
246 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
247 #define ABSTRACT_STMT(type)
248 #define STMT(type, base) \
249 case Stmt::type##Class: \
250 return getSourceRangeImpl<type>(this, &type::getSourceRange);
251 #include "clang/AST/StmtNodes.inc"
253 llvm_unreachable("unknown statement kind!");
256 SourceLocation Stmt::getLocStart() const {
257 // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
258 switch (getStmtClass()) {
259 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
260 #define ABSTRACT_STMT(type)
261 #define STMT(type, base) \
262 case Stmt::type##Class: \
263 return static_cast<const type*>(this)->getLocStart();
264 #include "clang/AST/StmtNodes.inc"
266 llvm_unreachable("unknown statement kind");
269 SourceLocation Stmt::getLocEnd() const {
270 switch (getStmtClass()) {
271 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
272 #define ABSTRACT_STMT(type)
273 #define STMT(type, base) \
274 case Stmt::type##Class: \
275 return static_cast<const type*>(this)->getLocEnd();
276 #include "clang/AST/StmtNodes.inc"
278 llvm_unreachable("unknown statement kind");
281 CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
282 SourceLocation LB, SourceLocation RB)
283 : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
284 CompoundStmtBits.NumStmts = Stmts.size();
285 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
286 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
288 if (Stmts.size() == 0) {
293 Body = new (C) Stmt*[Stmts.size()];
294 std::copy(Stmts.begin(), Stmts.end(), Body);
297 void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts,
301 this->CompoundStmtBits.NumStmts = NumStmts;
303 Body = new (C) Stmt*[NumStmts];
304 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
307 const char *LabelStmt::getName() const {
308 return getDecl()->getIdentifier()->getNameStart();
311 AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
312 ArrayRef<const Attr*> Attrs,
314 assert(!Attrs.empty() && "Attrs should not be empty");
315 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
316 llvm::alignOf<AttributedStmt>());
317 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
320 AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
322 assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
323 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
324 llvm::alignOf<AttributedStmt>());
325 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
328 std::string AsmStmt::generateAsmString(const ASTContext &C) const {
329 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
330 return gccAsmStmt->generateAsmString(C);
331 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
332 return msAsmStmt->generateAsmString(C);
333 llvm_unreachable("unknown asm statement kind!");
336 StringRef AsmStmt::getOutputConstraint(unsigned i) const {
337 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
338 return gccAsmStmt->getOutputConstraint(i);
339 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
340 return msAsmStmt->getOutputConstraint(i);
341 llvm_unreachable("unknown asm statement kind!");
344 const Expr *AsmStmt::getOutputExpr(unsigned i) const {
345 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
346 return gccAsmStmt->getOutputExpr(i);
347 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
348 return msAsmStmt->getOutputExpr(i);
349 llvm_unreachable("unknown asm statement kind!");
352 StringRef AsmStmt::getInputConstraint(unsigned i) const {
353 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
354 return gccAsmStmt->getInputConstraint(i);
355 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
356 return msAsmStmt->getInputConstraint(i);
357 llvm_unreachable("unknown asm statement kind!");
360 const Expr *AsmStmt::getInputExpr(unsigned i) const {
361 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
362 return gccAsmStmt->getInputExpr(i);
363 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
364 return msAsmStmt->getInputExpr(i);
365 llvm_unreachable("unknown asm statement kind!");
368 StringRef AsmStmt::getClobber(unsigned i) const {
369 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
370 return gccAsmStmt->getClobber(i);
371 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
372 return msAsmStmt->getClobber(i);
373 llvm_unreachable("unknown asm statement kind!");
376 /// getNumPlusOperands - Return the number of output operands that have a "+"
378 unsigned AsmStmt::getNumPlusOperands() const {
380 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
381 if (isOutputPlusConstraint(i))
386 char GCCAsmStmt::AsmStringPiece::getModifier() const {
387 assert(isOperand() && "Only Operands can have modifiers.");
388 return isLetter(Str[0]) ? Str[0] : '\0';
391 StringRef GCCAsmStmt::getClobber(unsigned i) const {
392 return getClobberStringLiteral(i)->getString();
395 Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
396 return cast<Expr>(Exprs[i]);
399 /// getOutputConstraint - Return the constraint string for the specified
400 /// output operand. All output constraints are known to be non-empty (either
402 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
403 return getOutputConstraintLiteral(i)->getString();
406 Expr *GCCAsmStmt::getInputExpr(unsigned i) {
407 return cast<Expr>(Exprs[i + NumOutputs]);
409 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
410 Exprs[i + NumOutputs] = E;
413 /// getInputConstraint - Return the specified input constraint. Unlike output
414 /// constraints, these can be empty.
415 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
416 return getInputConstraintLiteral(i)->getString();
419 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
420 IdentifierInfo **Names,
421 StringLiteral **Constraints,
425 StringLiteral **Clobbers,
426 unsigned NumClobbers) {
427 this->NumOutputs = NumOutputs;
428 this->NumInputs = NumInputs;
429 this->NumClobbers = NumClobbers;
431 unsigned NumExprs = NumOutputs + NumInputs;
433 C.Deallocate(this->Names);
434 this->Names = new (C) IdentifierInfo*[NumExprs];
435 std::copy(Names, Names + NumExprs, this->Names);
437 C.Deallocate(this->Exprs);
438 this->Exprs = new (C) Stmt*[NumExprs];
439 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
441 C.Deallocate(this->Constraints);
442 this->Constraints = new (C) StringLiteral*[NumExprs];
443 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
445 C.Deallocate(this->Clobbers);
446 this->Clobbers = new (C) StringLiteral*[NumClobbers];
447 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
450 /// getNamedOperand - Given a symbolic operand reference like %[foo],
451 /// translate this into a numeric value needed to reference the same operand.
452 /// This returns -1 if the operand name is invalid.
453 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
454 unsigned NumPlusOperands = 0;
456 // Check if this is an output operand.
457 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
458 if (getOutputName(i) == SymbolicName)
462 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
463 if (getInputName(i) == SymbolicName)
464 return getNumOutputs() + NumPlusOperands + i;
470 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
471 /// it into pieces. If the asm string is erroneous, emit errors and return
472 /// true, otherwise return false.
473 unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
474 const ASTContext &C, unsigned &DiagOffs) const {
475 StringRef Str = getAsmString()->getString();
476 const char *StrStart = Str.begin();
477 const char *StrEnd = Str.end();
478 const char *CurPtr = StrStart;
480 // "Simple" inline asms have no constraints or operands, just convert the asm
481 // string to escape $'s.
484 for (; CurPtr != StrEnd; ++CurPtr) {
494 Pieces.push_back(AsmStringPiece(Result));
498 // CurStringPiece - The current string that we are building up as we scan the
500 std::string CurStringPiece;
502 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
505 // Done with the string?
506 if (CurPtr == StrEnd) {
507 if (!CurStringPiece.empty())
508 Pieces.push_back(AsmStringPiece(CurStringPiece));
512 char CurChar = *CurPtr++;
514 case '$': CurStringPiece += "$$"; continue;
515 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
516 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
517 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
521 CurStringPiece += CurChar;
525 // Escaped "%" character in asm string.
526 if (CurPtr == StrEnd) {
527 // % at end of string is invalid (no escape).
528 DiagOffs = CurPtr-StrStart-1;
529 return diag::err_asm_invalid_escape;
532 char EscapedChar = *CurPtr++;
533 if (EscapedChar == '%') { // %% -> %
534 // Escaped percentage sign.
535 CurStringPiece += '%';
539 if (EscapedChar == '=') { // %= -> Generate an unique ID.
540 CurStringPiece += "${:uid}";
544 // Otherwise, we have an operand. If we have accumulated a string so far,
545 // add it to the Pieces list.
546 if (!CurStringPiece.empty()) {
547 Pieces.push_back(AsmStringPiece(CurStringPiece));
548 CurStringPiece.clear();
551 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
552 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
554 const char *Begin = CurPtr - 1; // Points to the character following '%'.
555 const char *Percent = Begin - 1; // Points to '%'.
557 if (isLetter(EscapedChar)) {
558 if (CurPtr == StrEnd) { // Premature end.
559 DiagOffs = CurPtr-StrStart-1;
560 return diag::err_asm_invalid_escape;
562 EscapedChar = *CurPtr++;
565 const TargetInfo &TI = C.getTargetInfo();
566 const SourceManager &SM = C.getSourceManager();
567 const LangOptions &LO = C.getLangOpts();
569 // Handle operands that don't have asmSymbolicName (e.g., %x4).
570 if (isDigit(EscapedChar)) {
571 // %n - Assembler operand n
575 while (CurPtr != StrEnd && isDigit(*CurPtr))
576 N = N*10 + ((*CurPtr++)-'0');
578 unsigned NumOperands =
579 getNumOutputs() + getNumPlusOperands() + getNumInputs();
580 if (N >= NumOperands) {
581 DiagOffs = CurPtr-StrStart-1;
582 return diag::err_asm_invalid_operand_number;
585 // Str contains "x4" (Operand without the leading %).
586 std::string Str(Begin, CurPtr - Begin);
588 // (BeginLoc, EndLoc) represents the range of the operand we are currently
589 // processing. Unlike Str, the range includes the leading '%'.
590 SourceLocation BeginLoc =
591 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
592 SourceLocation EndLoc =
593 getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
595 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
599 // Handle operands that have asmSymbolicName (e.g., %x[foo]).
600 if (EscapedChar == '[') {
601 DiagOffs = CurPtr-StrStart-1;
604 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
605 if (NameEnd == nullptr)
606 return diag::err_asm_unterminated_symbolic_operand_name;
607 if (NameEnd == CurPtr)
608 return diag::err_asm_empty_symbolic_operand_name;
610 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
612 int N = getNamedOperand(SymbolicName);
614 // Verify that an operand with that name exists.
615 DiagOffs = CurPtr-StrStart;
616 return diag::err_asm_unknown_symbolic_operand_name;
619 // Str contains "x[foo]" (Operand without the leading %).
620 std::string Str(Begin, NameEnd + 1 - Begin);
622 // (BeginLoc, EndLoc) represents the range of the operand we are currently
623 // processing. Unlike Str, the range includes the leading '%'.
624 SourceLocation BeginLoc =
625 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
626 SourceLocation EndLoc =
627 getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
629 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
635 DiagOffs = CurPtr-StrStart-1;
636 return diag::err_asm_invalid_escape;
640 /// Assemble final IR asm string (GCC-style).
641 std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
642 // Analyze the asm string to decompose it into its pieces. We know that Sema
643 // has already done this, so it is guaranteed to be successful.
644 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
646 AnalyzeAsmString(Pieces, C, DiagOffs);
648 std::string AsmString;
649 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
650 if (Pieces[i].isString())
651 AsmString += Pieces[i].getString();
652 else if (Pieces[i].getModifier() == '\0')
653 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
655 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
656 Pieces[i].getModifier() + '}';
661 /// Assemble final IR asm string (MS-style).
662 std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
663 // FIXME: This needs to be translated into the IR string representation.
667 Expr *MSAsmStmt::getOutputExpr(unsigned i) {
668 return cast<Expr>(Exprs[i]);
671 Expr *MSAsmStmt::getInputExpr(unsigned i) {
672 return cast<Expr>(Exprs[i + NumOutputs]);
674 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
675 Exprs[i + NumOutputs] = E;
678 QualType CXXCatchStmt::getCaughtType() const {
680 return ExceptionDecl->getType();
684 //===----------------------------------------------------------------------===//
686 //===----------------------------------------------------------------------===//
688 GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
689 bool issimple, bool isvolatile, unsigned numoutputs,
690 unsigned numinputs, IdentifierInfo **names,
691 StringLiteral **constraints, Expr **exprs,
692 StringLiteral *asmstr, unsigned numclobbers,
693 StringLiteral **clobbers, SourceLocation rparenloc)
694 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
695 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
697 unsigned NumExprs = NumOutputs + NumInputs;
699 Names = new (C) IdentifierInfo*[NumExprs];
700 std::copy(names, names + NumExprs, Names);
702 Exprs = new (C) Stmt*[NumExprs];
703 std::copy(exprs, exprs + NumExprs, Exprs);
705 Constraints = new (C) StringLiteral*[NumExprs];
706 std::copy(constraints, constraints + NumExprs, Constraints);
708 Clobbers = new (C) StringLiteral*[NumClobbers];
709 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
712 MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
713 SourceLocation lbraceloc, bool issimple, bool isvolatile,
714 ArrayRef<Token> asmtoks, unsigned numoutputs,
716 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
717 StringRef asmstr, ArrayRef<StringRef> clobbers,
718 SourceLocation endloc)
719 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
720 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
721 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
723 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
726 static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
727 size_t size = str.size();
728 char *buffer = new (C) char[size];
729 memcpy(buffer, str.data(), size);
730 return StringRef(buffer, size);
733 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
734 ArrayRef<Token> asmtoks,
735 ArrayRef<StringRef> constraints,
736 ArrayRef<Expr*> exprs,
737 ArrayRef<StringRef> clobbers) {
738 assert(NumAsmToks == asmtoks.size());
739 assert(NumClobbers == clobbers.size());
741 unsigned NumExprs = exprs.size();
742 assert(NumExprs == NumOutputs + NumInputs);
743 assert(NumExprs == constraints.size());
745 AsmStr = copyIntoContext(C, asmstr);
747 Exprs = new (C) Stmt*[NumExprs];
748 for (unsigned i = 0, e = NumExprs; i != e; ++i)
751 AsmToks = new (C) Token[NumAsmToks];
752 for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
753 AsmToks[i] = asmtoks[i];
755 Constraints = new (C) StringRef[NumExprs];
756 for (unsigned i = 0, e = NumExprs; i != e; ++i) {
757 Constraints[i] = copyIntoContext(C, constraints[i]);
760 Clobbers = new (C) StringRef[NumClobbers];
761 for (unsigned i = 0, e = NumClobbers; i != e; ++i) {
762 // FIXME: Avoid the allocation/copy if at all possible.
763 Clobbers[i] = copyIntoContext(C, clobbers[i]);
767 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
768 Stmt *Body, SourceLocation FCL,
770 : Stmt(ObjCForCollectionStmtClass) {
771 SubExprs[ELEM] = Elem;
772 SubExprs[COLLECTION] = Collect;
773 SubExprs[BODY] = Body;
778 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
779 Stmt **CatchStmts, unsigned NumCatchStmts,
781 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
782 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) {
783 Stmt **Stmts = getStmts();
784 Stmts[0] = atTryStmt;
785 for (unsigned I = 0; I != NumCatchStmts; ++I)
786 Stmts[I + 1] = CatchStmts[I];
789 Stmts[NumCatchStmts + 1] = atFinallyStmt;
792 ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
793 SourceLocation atTryLoc,
796 unsigned NumCatchStmts,
797 Stmt *atFinallyStmt) {
798 unsigned Size = sizeof(ObjCAtTryStmt) +
799 (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
800 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
801 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
805 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
806 unsigned NumCatchStmts,
808 unsigned Size = sizeof(ObjCAtTryStmt) +
809 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
810 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
811 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
814 SourceLocation ObjCAtTryStmt::getLocEnd() const {
816 return getFinallyStmt()->getLocEnd();
818 return getCatchStmt(NumCatchStmts - 1)->getLocEnd();
819 return getTryBody()->getLocEnd();
822 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
823 Stmt *tryBlock, ArrayRef<Stmt*> handlers) {
824 std::size_t Size = sizeof(CXXTryStmt);
825 Size += ((handlers.size() + 1) * sizeof(Stmt));
827 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
828 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
831 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
832 unsigned numHandlers) {
833 std::size_t Size = sizeof(CXXTryStmt);
834 Size += ((numHandlers + 1) * sizeof(Stmt));
836 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
837 return new (Mem) CXXTryStmt(Empty, numHandlers);
840 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
841 ArrayRef<Stmt*> handlers)
842 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
843 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
845 std::copy(handlers.begin(), handlers.end(), Stmts + 1);
848 CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
849 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
850 Stmt *Body, SourceLocation FL,
851 SourceLocation CL, SourceLocation RPL)
852 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
853 SubExprs[RANGE] = Range;
854 SubExprs[BEGINEND] = BeginEndStmt;
855 SubExprs[COND] = Cond;
857 SubExprs[LOOPVAR] = LoopVar;
858 SubExprs[BODY] = Body;
861 Expr *CXXForRangeStmt::getRangeInit() {
862 DeclStmt *RangeStmt = getRangeStmt();
863 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
864 assert(RangeDecl && "for-range should have a single var decl");
865 return RangeDecl->getInit();
868 const Expr *CXXForRangeStmt::getRangeInit() const {
869 return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
872 VarDecl *CXXForRangeStmt::getLoopVariable() {
873 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
874 assert(LV && "No loop variable in CXXForRangeStmt");
875 return cast<VarDecl>(LV);
878 const VarDecl *CXXForRangeStmt::getLoopVariable() const {
879 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
882 IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
883 Stmt *then, SourceLocation EL, Stmt *elsev)
884 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
886 setConditionVariable(C, var);
887 SubExprs[COND] = cond;
888 SubExprs[THEN] = then;
889 SubExprs[ELSE] = elsev;
892 VarDecl *IfStmt::getConditionVariable() const {
896 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
897 return cast<VarDecl>(DS->getSingleDecl());
900 void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
902 SubExprs[VAR] = nullptr;
906 SourceRange VarRange = V->getSourceRange();
907 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
911 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
912 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
914 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
916 SubExprs[INIT] = Init;
917 setConditionVariable(C, condVar);
918 SubExprs[COND] = Cond;
920 SubExprs[BODY] = Body;
923 VarDecl *ForStmt::getConditionVariable() const {
924 if (!SubExprs[CONDVAR])
927 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
928 return cast<VarDecl>(DS->getSingleDecl());
931 void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
933 SubExprs[CONDVAR] = nullptr;
937 SourceRange VarRange = V->getSourceRange();
938 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
942 SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
943 : Stmt(SwitchStmtClass), FirstCase(nullptr, false) {
944 setConditionVariable(C, Var);
945 SubExprs[COND] = cond;
946 SubExprs[BODY] = nullptr;
949 VarDecl *SwitchStmt::getConditionVariable() const {
953 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
954 return cast<VarDecl>(DS->getSingleDecl());
957 void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
959 SubExprs[VAR] = nullptr;
963 SourceRange VarRange = V->getSourceRange();
964 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
968 Stmt *SwitchCase::getSubStmt() {
969 if (isa<CaseStmt>(this))
970 return cast<CaseStmt>(this)->getSubStmt();
971 return cast<DefaultStmt>(this)->getSubStmt();
974 WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
976 : Stmt(WhileStmtClass) {
977 setConditionVariable(C, Var);
978 SubExprs[COND] = cond;
979 SubExprs[BODY] = body;
983 VarDecl *WhileStmt::getConditionVariable() const {
987 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
988 return cast<VarDecl>(DS->getSingleDecl());
991 void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
993 SubExprs[VAR] = nullptr;
997 SourceRange VarRange = V->getSourceRange();
998 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
1003 LabelDecl *IndirectGotoStmt::getConstantTarget() {
1004 if (AddrLabelExpr *E =
1005 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1006 return E->getLabel();
1011 const Expr* ReturnStmt::getRetValue() const {
1012 return cast_or_null<Expr>(RetExpr);
1014 Expr* ReturnStmt::getRetValue() {
1015 return cast_or_null<Expr>(RetExpr);
1018 SEHTryStmt::SEHTryStmt(bool IsCXXTry,
1019 SourceLocation TryLoc,
1022 : Stmt(SEHTryStmtClass),
1026 Children[TRY] = TryBlock;
1027 Children[HANDLER] = Handler;
1030 SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
1031 SourceLocation TryLoc, Stmt *TryBlock,
1033 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
1036 SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
1037 return dyn_cast<SEHExceptStmt>(getHandler());
1040 SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
1041 return dyn_cast<SEHFinallyStmt>(getHandler());
1044 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
1047 : Stmt(SEHExceptStmtClass),
1050 Children[FILTER_EXPR] = FilterExpr;
1051 Children[BLOCK] = Block;
1054 SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
1055 Expr *FilterExpr, Stmt *Block) {
1056 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
1059 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
1061 : Stmt(SEHFinallyStmtClass),
1066 SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
1068 return new(C)SEHFinallyStmt(Loc,Block);
1071 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
1072 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1074 // Offset of the first Capture object.
1075 unsigned FirstCaptureOffset =
1076 llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1078 return reinterpret_cast<Capture *>(
1079 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1080 + FirstCaptureOffset);
1083 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1084 ArrayRef<Capture> Captures,
1085 ArrayRef<Expr *> CaptureInits,
1088 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
1089 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
1090 assert( S && "null captured statement");
1091 assert(CD && "null captured declaration for captured statement");
1092 assert(RD && "null record declaration for captured statement");
1094 // Copy initialization expressions.
1095 Stmt **Stored = getStoredStmts();
1096 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1097 *Stored++ = CaptureInits[I];
1099 // Copy the statement being captured.
1102 // Copy all Capture objects.
1103 Capture *Buffer = getStoredCaptures();
1104 std::copy(Captures.begin(), Captures.end(), Buffer);
1107 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1108 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1109 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
1110 getStoredStmts()[NumCaptures] = nullptr;
1113 CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
1114 CapturedRegionKind Kind,
1115 ArrayRef<Capture> Captures,
1116 ArrayRef<Expr *> CaptureInits,
1121 // -----------------------------------------------------------
1122 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1123 // ----------------^-------------------^----------------------
1124 // getStoredStmts() getStoredCaptures()
1126 // where S is the statement being captured.
1128 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1130 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1131 if (!Captures.empty()) {
1132 // Realign for the following Capture array.
1133 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1134 Size += sizeof(Capture) * Captures.size();
1137 void *Mem = Context.Allocate(Size);
1138 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1141 CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
1142 unsigned NumCaptures) {
1143 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1144 if (NumCaptures > 0) {
1145 // Realign for the following Capture array.
1146 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1147 Size += sizeof(Capture) * NumCaptures;
1150 void *Mem = Context.Allocate(Size);
1151 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1154 Stmt::child_range CapturedStmt::children() {
1155 // Children are captured field initilizers.
1156 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1159 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
1160 for (const auto &I : captures()) {
1161 if (!I.capturesVariable())
1164 // This does not handle variable redeclarations. This should be
1165 // extended to capture variables with redeclarations, for example
1166 // a thread-private variable in OpenMP.
1167 if (I.getCapturedVar() == Var)
1174 StmtRange OMPClause::children() {
1175 switch(getClauseKind()) {
1177 #define OPENMP_CLAUSE(Name, Class) \
1178 case OMPC_ ## Name : return static_cast<Class *>(this)->children();
1179 #include "clang/Basic/OpenMPKinds.def"
1181 llvm_unreachable("unknown OMPClause");
1184 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1185 assert(VL.size() == varlist_size() &&
1186 "Number of private copies is not the same as the preallocated buffer");
1187 std::copy(VL.begin(), VL.end(), varlist_end());
1191 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
1192 SourceLocation LParenLoc, SourceLocation EndLoc,
1193 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
1194 // Allocate space for private variables and initializer expressions.
1195 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1196 llvm::alignOf<Expr *>()) +
1197 2 * sizeof(Expr *) * VL.size());
1198 OMPPrivateClause *Clause =
1199 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1200 Clause->setVarRefs(VL);
1201 Clause->setPrivateCopies(PrivateVL);
1205 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
1207 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1208 llvm::alignOf<Expr *>()) +
1209 2 * sizeof(Expr *) * N);
1210 return new (Mem) OMPPrivateClause(N);
1213 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1214 assert(VL.size() == varlist_size() &&
1215 "Number of private copies is not the same as the preallocated buffer");
1216 std::copy(VL.begin(), VL.end(), varlist_end());
1219 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
1220 assert(VL.size() == varlist_size() &&
1221 "Number of inits is not the same as the preallocated buffer");
1222 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1225 OMPFirstprivateClause *
1226 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
1227 SourceLocation LParenLoc, SourceLocation EndLoc,
1228 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1229 ArrayRef<Expr *> InitVL) {
1230 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1231 llvm::alignOf<Expr *>()) +
1232 3 * sizeof(Expr *) * VL.size());
1233 OMPFirstprivateClause *Clause =
1234 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1235 Clause->setVarRefs(VL);
1236 Clause->setPrivateCopies(PrivateVL);
1237 Clause->setInits(InitVL);
1241 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
1243 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1244 llvm::alignOf<Expr *>()) +
1245 3 * sizeof(Expr *) * N);
1246 return new (Mem) OMPFirstprivateClause(N);
1249 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
1250 assert(PrivateCopies.size() == varlist_size() &&
1251 "Number of private copies is not the same as the preallocated buffer");
1252 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
1255 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1256 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1257 "not the same as the "
1258 "preallocated buffer");
1259 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
1262 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1263 assert(DstExprs.size() == varlist_size() && "Number of destination "
1264 "expressions is not the same as "
1265 "the preallocated buffer");
1266 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1269 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1270 assert(AssignmentOps.size() == varlist_size() &&
1271 "Number of assignment expressions is not the same as the preallocated "
1273 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1274 getDestinationExprs().end());
1277 OMPLastprivateClause *OMPLastprivateClause::Create(
1278 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1279 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1280 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
1281 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1282 llvm::alignOf<Expr *>()) +
1283 5 * sizeof(Expr *) * VL.size());
1284 OMPLastprivateClause *Clause =
1285 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1286 Clause->setVarRefs(VL);
1287 Clause->setSourceExprs(SrcExprs);
1288 Clause->setDestinationExprs(DstExprs);
1289 Clause->setAssignmentOps(AssignmentOps);
1293 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
1295 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1296 llvm::alignOf<Expr *>()) +
1297 5 * sizeof(Expr *) * N);
1298 return new (Mem) OMPLastprivateClause(N);
1301 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
1302 SourceLocation StartLoc,
1303 SourceLocation LParenLoc,
1304 SourceLocation EndLoc,
1305 ArrayRef<Expr *> VL) {
1306 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1307 llvm::alignOf<Expr *>()) +
1308 sizeof(Expr *) * VL.size());
1309 OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
1311 Clause->setVarRefs(VL);
1315 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
1317 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1318 llvm::alignOf<Expr *>()) +
1319 sizeof(Expr *) * N);
1320 return new (Mem) OMPSharedClause(N);
1323 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
1324 assert(IL.size() == varlist_size() &&
1325 "Number of inits is not the same as the preallocated buffer");
1326 std::copy(IL.begin(), IL.end(), varlist_end());
1329 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
1330 assert(UL.size() == varlist_size() &&
1331 "Number of updates is not the same as the preallocated buffer");
1332 std::copy(UL.begin(), UL.end(), getInits().end());
1335 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
1336 assert(FL.size() == varlist_size() &&
1337 "Number of final updates is not the same as the preallocated buffer");
1338 std::copy(FL.begin(), FL.end(), getUpdates().end());
1342 OMPLinearClause::Create(const ASTContext &C, SourceLocation StartLoc,
1343 SourceLocation LParenLoc, SourceLocation ColonLoc,
1344 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1345 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) {
1346 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
1347 // (Step and CalcStep).
1348 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1349 llvm::alignOf<Expr *>()) +
1350 (4 * VL.size() + 2) * sizeof(Expr *));
1351 OMPLinearClause *Clause = new (Mem)
1352 OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1353 Clause->setVarRefs(VL);
1354 Clause->setInits(IL);
1355 // Fill update and final expressions with zeroes, they are provided later,
1356 // after the directive construction.
1357 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
1359 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
1361 Clause->setStep(Step);
1362 Clause->setCalcStep(CalcStep);
1366 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
1368 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
1369 // (Step and CalcStep).
1370 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1371 llvm::alignOf<Expr *>()) +
1372 (4 * NumVars + 2) * sizeof(Expr *));
1373 return new (Mem) OMPLinearClause(NumVars);
1377 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
1378 SourceLocation LParenLoc, SourceLocation ColonLoc,
1379 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
1380 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1381 llvm::alignOf<Expr *>()) +
1382 sizeof(Expr *) * (VL.size() + 1));
1383 OMPAlignedClause *Clause = new (Mem)
1384 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1385 Clause->setVarRefs(VL);
1386 Clause->setAlignment(A);
1390 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
1392 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1393 llvm::alignOf<Expr *>()) +
1394 sizeof(Expr *) * (NumVars + 1));
1395 return new (Mem) OMPAlignedClause(NumVars);
1398 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1399 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1400 "not the same as the "
1401 "preallocated buffer");
1402 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
1405 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1406 assert(DstExprs.size() == varlist_size() && "Number of destination "
1407 "expressions is not the same as "
1408 "the preallocated buffer");
1409 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1412 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1413 assert(AssignmentOps.size() == varlist_size() &&
1414 "Number of assignment expressions is not the same as the preallocated "
1416 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1417 getDestinationExprs().end());
1420 OMPCopyinClause *OMPCopyinClause::Create(
1421 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1422 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1423 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
1424 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1425 llvm::alignOf<Expr *>()) +
1426 4 * sizeof(Expr *) * VL.size());
1427 OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc,
1429 Clause->setVarRefs(VL);
1430 Clause->setSourceExprs(SrcExprs);
1431 Clause->setDestinationExprs(DstExprs);
1432 Clause->setAssignmentOps(AssignmentOps);
1436 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C,
1438 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1439 llvm::alignOf<Expr *>()) +
1440 4 * sizeof(Expr *) * N);
1441 return new (Mem) OMPCopyinClause(N);
1444 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1445 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1446 "not the same as the "
1447 "preallocated buffer");
1448 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
1451 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1452 assert(DstExprs.size() == varlist_size() && "Number of destination "
1453 "expressions is not the same as "
1454 "the preallocated buffer");
1455 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1458 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1459 assert(AssignmentOps.size() == varlist_size() &&
1460 "Number of assignment expressions is not the same as the preallocated "
1462 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1463 getDestinationExprs().end());
1466 OMPCopyprivateClause *OMPCopyprivateClause::Create(
1467 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1468 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1469 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
1470 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1471 llvm::alignOf<Expr *>()) +
1472 4 * sizeof(Expr *) * VL.size());
1473 OMPCopyprivateClause *Clause =
1474 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1475 Clause->setVarRefs(VL);
1476 Clause->setSourceExprs(SrcExprs);
1477 Clause->setDestinationExprs(DstExprs);
1478 Clause->setAssignmentOps(AssignmentOps);
1482 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
1484 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1485 llvm::alignOf<Expr *>()) +
1486 4 * sizeof(Expr *) * N);
1487 return new (Mem) OMPCopyprivateClause(N);
1490 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
1491 assert(Clauses.size() == getNumClauses() &&
1492 "Number of clauses is not the same as the preallocated buffer");
1493 std::copy(Clauses.begin(), Clauses.end(), getClauses().begin());
1496 void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) {
1497 assert(A.size() == getCollapsedNumber() &&
1498 "Number of loop counters is not the same as the collapsed number");
1499 std::copy(A.begin(), A.end(), getCounters().begin());
1502 void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) {
1503 assert(A.size() == getCollapsedNumber() &&
1504 "Number of counter updates is not the same as the collapsed number");
1505 std::copy(A.begin(), A.end(), getUpdates().begin());
1508 void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) {
1509 assert(A.size() == getCollapsedNumber() &&
1510 "Number of counter finals is not the same as the collapsed number");
1511 std::copy(A.begin(), A.end(), getFinals().begin());
1514 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
1516 LHSExprs.size() == varlist_size() &&
1517 "Number of LHS expressions is not the same as the preallocated buffer");
1518 std::copy(LHSExprs.begin(), LHSExprs.end(), varlist_end());
1521 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
1523 RHSExprs.size() == varlist_size() &&
1524 "Number of RHS expressions is not the same as the preallocated buffer");
1525 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
1528 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
1529 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
1530 "expressions is not the same "
1531 "as the preallocated buffer");
1532 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
1535 OMPReductionClause *OMPReductionClause::Create(
1536 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1537 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
1538 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
1539 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1540 ArrayRef<Expr *> ReductionOps) {
1541 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1542 llvm::alignOf<Expr *>()) +
1543 4 * sizeof(Expr *) * VL.size());
1544 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
1545 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
1546 Clause->setVarRefs(VL);
1547 Clause->setLHSExprs(LHSExprs);
1548 Clause->setRHSExprs(RHSExprs);
1549 Clause->setReductionOps(ReductionOps);
1553 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
1555 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1556 llvm::alignOf<Expr *>()) +
1557 4 * sizeof(Expr *) * N);
1558 return new (Mem) OMPReductionClause(N);
1561 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
1562 SourceLocation StartLoc,
1563 SourceLocation LParenLoc,
1564 SourceLocation EndLoc,
1565 ArrayRef<Expr *> VL) {
1566 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1567 llvm::alignOf<Expr *>()) +
1568 sizeof(Expr *) * VL.size());
1569 OMPFlushClause *Clause =
1570 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
1571 Clause->setVarRefs(VL);
1575 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
1576 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1577 llvm::alignOf<Expr *>()) +
1578 sizeof(Expr *) * N);
1579 return new (Mem) OMPFlushClause(N);
1583 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
1584 SourceLocation LParenLoc, SourceLocation EndLoc,
1585 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1586 SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
1587 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause),
1588 llvm::alignOf<Expr *>()) +
1589 sizeof(Expr *) * VL.size());
1590 OMPDependClause *Clause =
1591 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
1592 Clause->setVarRefs(VL);
1593 Clause->setDependencyKind(DepKind);
1594 Clause->setDependencyLoc(DepLoc);
1595 Clause->setColonLoc(ColonLoc);
1599 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
1600 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause),
1601 llvm::alignOf<Expr *>()) +
1602 sizeof(Expr *) * N);
1603 return new (Mem) OMPDependClause(N);
1607 OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const {
1608 auto &&I = getClausesOfKind(K);
1612 assert(!++I && "There are at least 2 clauses of the specified kind");
1618 OMPParallelDirective *OMPParallelDirective::Create(
1619 const ASTContext &C,
1620 SourceLocation StartLoc,
1621 SourceLocation EndLoc,
1622 ArrayRef<OMPClause *> Clauses,
1623 Stmt *AssociatedStmt) {
1624 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1625 llvm::alignOf<OMPClause *>());
1626 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1628 OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc,
1630 Dir->setClauses(Clauses);
1631 Dir->setAssociatedStmt(AssociatedStmt);
1635 OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
1636 unsigned NumClauses,
1638 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1639 llvm::alignOf<OMPClause *>());
1640 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1642 return new (Mem) OMPParallelDirective(NumClauses);
1646 OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1647 SourceLocation EndLoc, unsigned CollapsedNum,
1648 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1649 const HelperExprs &Exprs) {
1650 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1651 llvm::alignOf<OMPClause *>());
1653 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1654 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
1655 OMPSimdDirective *Dir = new (Mem)
1656 OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1657 Dir->setClauses(Clauses);
1658 Dir->setAssociatedStmt(AssociatedStmt);
1659 Dir->setIterationVariable(Exprs.IterationVarRef);
1660 Dir->setLastIteration(Exprs.LastIteration);
1661 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1662 Dir->setPreCond(Exprs.PreCond);
1663 Dir->setCond(Exprs.Cond);
1664 Dir->setInit(Exprs.Init);
1665 Dir->setInc(Exprs.Inc);
1666 Dir->setCounters(Exprs.Counters);
1667 Dir->setUpdates(Exprs.Updates);
1668 Dir->setFinals(Exprs.Finals);
1672 OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
1673 unsigned NumClauses,
1674 unsigned CollapsedNum,
1676 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1677 llvm::alignOf<OMPClause *>());
1679 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1680 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
1681 return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses);
1685 OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1686 SourceLocation EndLoc, unsigned CollapsedNum,
1687 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1688 const HelperExprs &Exprs) {
1689 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1690 llvm::alignOf<OMPClause *>());
1692 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1693 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
1694 OMPForDirective *Dir =
1695 new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1696 Dir->setClauses(Clauses);
1697 Dir->setAssociatedStmt(AssociatedStmt);
1698 Dir->setIterationVariable(Exprs.IterationVarRef);
1699 Dir->setLastIteration(Exprs.LastIteration);
1700 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1701 Dir->setPreCond(Exprs.PreCond);
1702 Dir->setCond(Exprs.Cond);
1703 Dir->setInit(Exprs.Init);
1704 Dir->setInc(Exprs.Inc);
1705 Dir->setIsLastIterVariable(Exprs.IL);
1706 Dir->setLowerBoundVariable(Exprs.LB);
1707 Dir->setUpperBoundVariable(Exprs.UB);
1708 Dir->setStrideVariable(Exprs.ST);
1709 Dir->setEnsureUpperBound(Exprs.EUB);
1710 Dir->setNextLowerBound(Exprs.NLB);
1711 Dir->setNextUpperBound(Exprs.NUB);
1712 Dir->setCounters(Exprs.Counters);
1713 Dir->setUpdates(Exprs.Updates);
1714 Dir->setFinals(Exprs.Finals);
1718 OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
1719 unsigned NumClauses,
1720 unsigned CollapsedNum,
1722 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1723 llvm::alignOf<OMPClause *>());
1725 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1726 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
1727 return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
1730 OMPForSimdDirective *
1731 OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1732 SourceLocation EndLoc, unsigned CollapsedNum,
1733 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1734 const HelperExprs &Exprs) {
1735 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1736 llvm::alignOf<OMPClause *>());
1738 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1739 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
1740 OMPForSimdDirective *Dir = new (Mem)
1741 OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1742 Dir->setClauses(Clauses);
1743 Dir->setAssociatedStmt(AssociatedStmt);
1744 Dir->setIterationVariable(Exprs.IterationVarRef);
1745 Dir->setLastIteration(Exprs.LastIteration);
1746 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1747 Dir->setPreCond(Exprs.PreCond);
1748 Dir->setCond(Exprs.Cond);
1749 Dir->setInit(Exprs.Init);
1750 Dir->setInc(Exprs.Inc);
1751 Dir->setIsLastIterVariable(Exprs.IL);
1752 Dir->setLowerBoundVariable(Exprs.LB);
1753 Dir->setUpperBoundVariable(Exprs.UB);
1754 Dir->setStrideVariable(Exprs.ST);
1755 Dir->setEnsureUpperBound(Exprs.EUB);
1756 Dir->setNextLowerBound(Exprs.NLB);
1757 Dir->setNextUpperBound(Exprs.NUB);
1758 Dir->setCounters(Exprs.Counters);
1759 Dir->setUpdates(Exprs.Updates);
1760 Dir->setFinals(Exprs.Finals);
1764 OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C,
1765 unsigned NumClauses,
1766 unsigned CollapsedNum,
1768 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1769 llvm::alignOf<OMPClause *>());
1771 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1772 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
1773 return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
1776 OMPSectionsDirective *OMPSectionsDirective::Create(
1777 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1778 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
1779 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1780 llvm::alignOf<OMPClause *>());
1782 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1783 OMPSectionsDirective *Dir =
1784 new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
1785 Dir->setClauses(Clauses);
1786 Dir->setAssociatedStmt(AssociatedStmt);
1790 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
1791 unsigned NumClauses,
1793 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1794 llvm::alignOf<OMPClause *>());
1796 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1797 return new (Mem) OMPSectionsDirective(NumClauses);
1800 OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
1801 SourceLocation StartLoc,
1802 SourceLocation EndLoc,
1803 Stmt *AssociatedStmt) {
1804 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
1805 llvm::alignOf<Stmt *>());
1806 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1807 OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
1808 Dir->setAssociatedStmt(AssociatedStmt);
1812 OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
1814 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
1815 llvm::alignOf<Stmt *>());
1816 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1817 return new (Mem) OMPSectionDirective();
1820 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
1821 SourceLocation StartLoc,
1822 SourceLocation EndLoc,
1823 ArrayRef<OMPClause *> Clauses,
1824 Stmt *AssociatedStmt) {
1825 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1826 llvm::alignOf<OMPClause *>());
1828 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1829 OMPSingleDirective *Dir =
1830 new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size());
1831 Dir->setClauses(Clauses);
1832 Dir->setAssociatedStmt(AssociatedStmt);
1836 OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C,
1837 unsigned NumClauses,
1839 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1840 llvm::alignOf<OMPClause *>());
1842 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1843 return new (Mem) OMPSingleDirective(NumClauses);
1846 OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
1847 SourceLocation StartLoc,
1848 SourceLocation EndLoc,
1849 Stmt *AssociatedStmt) {
1850 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1851 llvm::alignOf<Stmt *>());
1852 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1853 OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc);
1854 Dir->setAssociatedStmt(AssociatedStmt);
1858 OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C,
1860 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1861 llvm::alignOf<Stmt *>());
1862 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1863 return new (Mem) OMPMasterDirective();
1866 OMPCriticalDirective *OMPCriticalDirective::Create(
1867 const ASTContext &C, const DeclarationNameInfo &Name,
1868 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) {
1869 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1870 llvm::alignOf<Stmt *>());
1871 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1872 OMPCriticalDirective *Dir =
1873 new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc);
1874 Dir->setAssociatedStmt(AssociatedStmt);
1878 OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C,
1880 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1881 llvm::alignOf<Stmt *>());
1882 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1883 return new (Mem) OMPCriticalDirective();
1886 OMPParallelForDirective *OMPParallelForDirective::Create(
1887 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1888 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1889 const HelperExprs &Exprs) {
1890 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1891 llvm::alignOf<OMPClause *>());
1892 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1894 numLoopChildren(CollapsedNum, OMPD_parallel_for));
1895 OMPParallelForDirective *Dir = new (Mem)
1896 OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1897 Dir->setClauses(Clauses);
1898 Dir->setAssociatedStmt(AssociatedStmt);
1899 Dir->setIterationVariable(Exprs.IterationVarRef);
1900 Dir->setLastIteration(Exprs.LastIteration);
1901 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1902 Dir->setPreCond(Exprs.PreCond);
1903 Dir->setCond(Exprs.Cond);
1904 Dir->setInit(Exprs.Init);
1905 Dir->setInc(Exprs.Inc);
1906 Dir->setIsLastIterVariable(Exprs.IL);
1907 Dir->setLowerBoundVariable(Exprs.LB);
1908 Dir->setUpperBoundVariable(Exprs.UB);
1909 Dir->setStrideVariable(Exprs.ST);
1910 Dir->setEnsureUpperBound(Exprs.EUB);
1911 Dir->setNextLowerBound(Exprs.NLB);
1912 Dir->setNextUpperBound(Exprs.NUB);
1913 Dir->setCounters(Exprs.Counters);
1914 Dir->setUpdates(Exprs.Updates);
1915 Dir->setFinals(Exprs.Finals);
1919 OMPParallelForDirective *
1920 OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
1921 unsigned CollapsedNum, EmptyShell) {
1922 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1923 llvm::alignOf<OMPClause *>());
1924 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1926 numLoopChildren(CollapsedNum, OMPD_parallel_for));
1927 return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses);
1930 OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create(
1931 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1932 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1933 const HelperExprs &Exprs) {
1934 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1935 llvm::alignOf<OMPClause *>());
1936 void *Mem = C.Allocate(
1937 Size + sizeof(OMPClause *) * Clauses.size() +
1938 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
1939 OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective(
1940 StartLoc, EndLoc, CollapsedNum, Clauses.size());
1941 Dir->setClauses(Clauses);
1942 Dir->setAssociatedStmt(AssociatedStmt);
1943 Dir->setIterationVariable(Exprs.IterationVarRef);
1944 Dir->setLastIteration(Exprs.LastIteration);
1945 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1946 Dir->setPreCond(Exprs.PreCond);
1947 Dir->setCond(Exprs.Cond);
1948 Dir->setInit(Exprs.Init);
1949 Dir->setInc(Exprs.Inc);
1950 Dir->setIsLastIterVariable(Exprs.IL);
1951 Dir->setLowerBoundVariable(Exprs.LB);
1952 Dir->setUpperBoundVariable(Exprs.UB);
1953 Dir->setStrideVariable(Exprs.ST);
1954 Dir->setEnsureUpperBound(Exprs.EUB);
1955 Dir->setNextLowerBound(Exprs.NLB);
1956 Dir->setNextUpperBound(Exprs.NUB);
1957 Dir->setCounters(Exprs.Counters);
1958 Dir->setUpdates(Exprs.Updates);
1959 Dir->setFinals(Exprs.Finals);
1963 OMPParallelForSimdDirective *
1964 OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C,
1965 unsigned NumClauses,
1966 unsigned CollapsedNum, EmptyShell) {
1967 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1968 llvm::alignOf<OMPClause *>());
1969 void *Mem = C.Allocate(
1970 Size + sizeof(OMPClause *) * NumClauses +
1971 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
1972 return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
1975 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
1976 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1977 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
1978 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
1979 llvm::alignOf<OMPClause *>());
1981 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1982 OMPParallelSectionsDirective *Dir =
1983 new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size());
1984 Dir->setClauses(Clauses);
1985 Dir->setAssociatedStmt(AssociatedStmt);
1989 OMPParallelSectionsDirective *
1990 OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C,
1991 unsigned NumClauses, EmptyShell) {
1992 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
1993 llvm::alignOf<OMPClause *>());
1995 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1996 return new (Mem) OMPParallelSectionsDirective(NumClauses);
1999 OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C,
2000 SourceLocation StartLoc,
2001 SourceLocation EndLoc,
2002 ArrayRef<OMPClause *> Clauses,
2003 Stmt *AssociatedStmt) {
2004 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
2005 llvm::alignOf<OMPClause *>());
2007 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2008 OMPTaskDirective *Dir =
2009 new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size());
2010 Dir->setClauses(Clauses);
2011 Dir->setAssociatedStmt(AssociatedStmt);
2015 OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C,
2016 unsigned NumClauses,
2018 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
2019 llvm::alignOf<OMPClause *>());
2021 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2022 return new (Mem) OMPTaskDirective(NumClauses);
2025 OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C,
2026 SourceLocation StartLoc,
2027 SourceLocation EndLoc) {
2028 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
2029 OMPTaskyieldDirective *Dir =
2030 new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc);
2034 OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
2036 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
2037 return new (Mem) OMPTaskyieldDirective();
2040 OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
2041 SourceLocation StartLoc,
2042 SourceLocation EndLoc) {
2043 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
2044 OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc);
2048 OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C,
2050 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
2051 return new (Mem) OMPBarrierDirective();
2054 OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C,
2055 SourceLocation StartLoc,
2056 SourceLocation EndLoc) {
2057 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
2058 OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc);
2062 OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C,
2064 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
2065 return new (Mem) OMPTaskwaitDirective();
2068 OMPTaskgroupDirective *OMPTaskgroupDirective::Create(const ASTContext &C,
2069 SourceLocation StartLoc,
2070 SourceLocation EndLoc,
2071 Stmt *AssociatedStmt) {
2072 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective),
2073 llvm::alignOf<Stmt *>());
2074 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2075 OMPTaskgroupDirective *Dir =
2076 new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc);
2077 Dir->setAssociatedStmt(AssociatedStmt);
2081 OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C,
2083 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective),
2084 llvm::alignOf<Stmt *>());
2085 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2086 return new (Mem) OMPTaskgroupDirective();
2089 OMPCancellationPointDirective *OMPCancellationPointDirective::Create(
2090 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2091 OpenMPDirectiveKind CancelRegion) {
2092 unsigned Size = llvm::RoundUpToAlignment(
2093 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>());
2094 void *Mem = C.Allocate(Size);
2095 OMPCancellationPointDirective *Dir =
2096 new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc);
2097 Dir->setCancelRegion(CancelRegion);
2101 OMPCancellationPointDirective *
2102 OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) {
2103 unsigned Size = llvm::RoundUpToAlignment(
2104 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>());
2105 void *Mem = C.Allocate(Size);
2106 return new (Mem) OMPCancellationPointDirective();
2109 OMPCancelDirective *
2110 OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc,
2111 SourceLocation EndLoc,
2112 OpenMPDirectiveKind CancelRegion) {
2113 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective),
2114 llvm::alignOf<Stmt *>());
2115 void *Mem = C.Allocate(Size);
2116 OMPCancelDirective *Dir = new (Mem) OMPCancelDirective(StartLoc, EndLoc);
2117 Dir->setCancelRegion(CancelRegion);
2121 OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C,
2123 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective),
2124 llvm::alignOf<Stmt *>());
2125 void *Mem = C.Allocate(Size);
2126 return new (Mem) OMPCancelDirective();
2129 OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C,
2130 SourceLocation StartLoc,
2131 SourceLocation EndLoc,
2132 ArrayRef<OMPClause *> Clauses) {
2133 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
2134 llvm::alignOf<OMPClause *>());
2135 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size());
2136 OMPFlushDirective *Dir =
2137 new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size());
2138 Dir->setClauses(Clauses);
2142 OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C,
2143 unsigned NumClauses,
2145 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
2146 llvm::alignOf<OMPClause *>());
2147 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses);
2148 return new (Mem) OMPFlushDirective(NumClauses);
2151 OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
2152 SourceLocation StartLoc,
2153 SourceLocation EndLoc,
2154 Stmt *AssociatedStmt) {
2155 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
2156 llvm::alignOf<Stmt *>());
2157 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2158 OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc);
2159 Dir->setAssociatedStmt(AssociatedStmt);
2163 OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C,
2165 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
2166 llvm::alignOf<Stmt *>());
2167 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2168 return new (Mem) OMPOrderedDirective();
2171 OMPAtomicDirective *OMPAtomicDirective::Create(
2172 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2173 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
2174 Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) {
2175 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
2176 llvm::alignOf<OMPClause *>());
2177 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
2178 5 * sizeof(Stmt *));
2179 OMPAtomicDirective *Dir =
2180 new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size());
2181 Dir->setClauses(Clauses);
2182 Dir->setAssociatedStmt(AssociatedStmt);
2186 Dir->setUpdateExpr(UE);
2187 Dir->IsXLHSInRHSPart = IsXLHSInRHSPart;
2188 Dir->IsPostfixUpdate = IsPostfixUpdate;
2192 OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C,
2193 unsigned NumClauses,
2195 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
2196 llvm::alignOf<OMPClause *>());
2198 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *));
2199 return new (Mem) OMPAtomicDirective(NumClauses);
2202 OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C,
2203 SourceLocation StartLoc,
2204 SourceLocation EndLoc,
2205 ArrayRef<OMPClause *> Clauses,
2206 Stmt *AssociatedStmt) {
2207 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
2208 llvm::alignOf<OMPClause *>());
2210 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2211 OMPTargetDirective *Dir =
2212 new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size());
2213 Dir->setClauses(Clauses);
2214 Dir->setAssociatedStmt(AssociatedStmt);
2218 OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C,
2219 unsigned NumClauses,
2221 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
2222 llvm::alignOf<OMPClause *>());
2224 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2225 return new (Mem) OMPTargetDirective(NumClauses);
2228 OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C,
2229 SourceLocation StartLoc,
2230 SourceLocation EndLoc,
2231 ArrayRef<OMPClause *> Clauses,
2232 Stmt *AssociatedStmt) {
2233 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
2234 llvm::alignOf<OMPClause *>());
2236 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2237 OMPTeamsDirective *Dir =
2238 new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size());
2239 Dir->setClauses(Clauses);
2240 Dir->setAssociatedStmt(AssociatedStmt);
2244 OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C,
2245 unsigned NumClauses,
2247 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
2248 llvm::alignOf<OMPClause *>());
2250 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2251 return new (Mem) OMPTeamsDirective(NumClauses);