1 //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the Stmt class and statement subclasses. 11 // 12 //===----------------------------------------------------------------------===// 13 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/ExprOpenMP.h" 19 #include "clang/AST/Stmt.h" 20 #include "clang/AST/StmtCXX.h" 21 #include "clang/AST/StmtObjC.h" 22 #include "clang/AST/StmtOpenMP.h" 23 #include "clang/AST/Type.h" 24 #include "clang/Basic/CharInfo.h" 25 #include "clang/Basic/TargetInfo.h" 26 #include "clang/Lex/Token.h" 27 #include "llvm/ADT/StringExtras.h" 28 #include "llvm/Support/raw_ostream.h" 29 using namespace clang; 30 31 static struct StmtClassNameTable { 32 const char *Name; 33 unsigned Counter; 34 unsigned Size; 35 } StmtClassInfo[Stmt::lastStmtConstant+1]; 36 37 static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { 38 static bool Initialized = false; 39 if (Initialized) 40 return StmtClassInfo[E]; 41 42 // Intialize the table on the first use. 43 Initialized = true; 44 #define ABSTRACT_STMT(STMT) 45 #define STMT(CLASS, PARENT) \ 46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ 47 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); 48 #include "clang/AST/StmtNodes.inc" 49 50 return StmtClassInfo[E]; 51 } 52 53 void *Stmt::operator new(size_t bytes, const ASTContext& C, 54 unsigned alignment) { 55 return ::operator new(bytes, C, alignment); 56 } 57 58 const char *Stmt::getStmtClassName() const { 59 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; 60 } 61 62 void Stmt::PrintStats() { 63 // Ensure the table is primed. 64 getStmtInfoTableEntry(Stmt::NullStmtClass); 65 66 unsigned sum = 0; 67 llvm::errs() << "\n*** Stmt/Expr Stats:\n"; 68 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { 69 if (StmtClassInfo[i].Name == nullptr) continue; 70 sum += StmtClassInfo[i].Counter; 71 } 72 llvm::errs() << " " << sum << " stmts/exprs total.\n"; 73 sum = 0; 74 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { 75 if (StmtClassInfo[i].Name == nullptr) continue; 76 if (StmtClassInfo[i].Counter == 0) continue; 77 llvm::errs() << " " << StmtClassInfo[i].Counter << " " 78 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size 79 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size 80 << " bytes)\n"; 81 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; 82 } 83 84 llvm::errs() << "Total bytes = " << sum << "\n"; 85 } 86 87 void Stmt::addStmtClass(StmtClass s) { 88 ++getStmtInfoTableEntry(s).Counter; 89 } 90 91 bool Stmt::StatisticsEnabled = false; 92 void Stmt::EnableStatistics() { 93 StatisticsEnabled = true; 94 } 95 96 Stmt *Stmt::IgnoreImplicit() { 97 Stmt *s = this; 98 99 if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) 100 s = ewc->getSubExpr(); 101 102 if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) 103 s = mte->GetTemporaryExpr(); 104 105 if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) 106 s = bte->getSubExpr(); 107 108 while (auto *ice = dyn_cast<ImplicitCastExpr>(s)) 109 s = ice->getSubExpr(); 110 111 return s; 112 } 113 114 /// \brief Skip no-op (attributed, compound) container stmts and skip captured 115 /// stmt at the top, if \a IgnoreCaptured is true. 116 Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { 117 Stmt *S = this; 118 if (IgnoreCaptured) 119 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S)) 120 S = CapS->getCapturedStmt(); 121 while (true) { 122 if (auto AS = dyn_cast_or_null<AttributedStmt>(S)) 123 S = AS->getSubStmt(); 124 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) { 125 if (CS->size() != 1) 126 break; 127 S = CS->body_back(); 128 } else 129 break; 130 } 131 return S; 132 } 133 134 /// \brief Strip off all label-like statements. 135 /// 136 /// This will strip off label statements, case statements, attributed 137 /// statements and default statements recursively. 138 const Stmt *Stmt::stripLabelLikeStatements() const { 139 const Stmt *S = this; 140 while (true) { 141 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) 142 S = LS->getSubStmt(); 143 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) 144 S = SC->getSubStmt(); 145 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) 146 S = AS->getSubStmt(); 147 else 148 return S; 149 } 150 } 151 152 namespace { 153 struct good {}; 154 struct bad {}; 155 156 // These silly little functions have to be static inline to suppress 157 // unused warnings, and they have to be defined to suppress other 158 // warnings. 159 static inline good is_good(good) { return good(); } 160 161 typedef Stmt::child_range children_t(); 162 template <class T> good implements_children(children_t T::*) { 163 return good(); 164 } 165 LLVM_ATTRIBUTE_UNUSED 166 static inline bad implements_children(children_t Stmt::*) { 167 return bad(); 168 } 169 170 typedef SourceLocation getLocStart_t() const; 171 template <class T> good implements_getLocStart(getLocStart_t T::*) { 172 return good(); 173 } 174 LLVM_ATTRIBUTE_UNUSED 175 static inline bad implements_getLocStart(getLocStart_t Stmt::*) { 176 return bad(); 177 } 178 179 typedef SourceLocation getLocEnd_t() const; 180 template <class T> good implements_getLocEnd(getLocEnd_t T::*) { 181 return good(); 182 } 183 LLVM_ATTRIBUTE_UNUSED 184 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { 185 return bad(); 186 } 187 188 #define ASSERT_IMPLEMENTS_children(type) \ 189 (void) is_good(implements_children(&type::children)) 190 #define ASSERT_IMPLEMENTS_getLocStart(type) \ 191 (void) is_good(implements_getLocStart(&type::getLocStart)) 192 #define ASSERT_IMPLEMENTS_getLocEnd(type) \ 193 (void) is_good(implements_getLocEnd(&type::getLocEnd)) 194 } 195 196 /// Check whether the various Stmt classes implement their member 197 /// functions. 198 LLVM_ATTRIBUTE_UNUSED 199 static inline void check_implementations() { 200 #define ABSTRACT_STMT(type) 201 #define STMT(type, base) \ 202 ASSERT_IMPLEMENTS_children(type); \ 203 ASSERT_IMPLEMENTS_getLocStart(type); \ 204 ASSERT_IMPLEMENTS_getLocEnd(type); 205 #include "clang/AST/StmtNodes.inc" 206 } 207 208 Stmt::child_range Stmt::children() { 209 switch (getStmtClass()) { 210 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 211 #define ABSTRACT_STMT(type) 212 #define STMT(type, base) \ 213 case Stmt::type##Class: \ 214 return static_cast<type*>(this)->children(); 215 #include "clang/AST/StmtNodes.inc" 216 } 217 llvm_unreachable("unknown statement kind!"); 218 } 219 220 // Amusing macro metaprogramming hack: check whether a class provides 221 // a more specific implementation of getSourceRange. 222 // 223 // See also Expr.cpp:getExprLoc(). 224 namespace { 225 /// This implementation is used when a class provides a custom 226 /// implementation of getSourceRange. 227 template <class S, class T> 228 SourceRange getSourceRangeImpl(const Stmt *stmt, 229 SourceRange (T::*v)() const) { 230 return static_cast<const S*>(stmt)->getSourceRange(); 231 } 232 233 /// This implementation is used when a class doesn't provide a custom 234 /// implementation of getSourceRange. Overload resolution should pick it over 235 /// the implementation above because it's more specialized according to 236 /// function template partial ordering. 237 template <class S> 238 SourceRange getSourceRangeImpl(const Stmt *stmt, 239 SourceRange (Stmt::*v)() const) { 240 return SourceRange(static_cast<const S*>(stmt)->getLocStart(), 241 static_cast<const S*>(stmt)->getLocEnd()); 242 } 243 } 244 245 SourceRange Stmt::getSourceRange() const { 246 switch (getStmtClass()) { 247 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 248 #define ABSTRACT_STMT(type) 249 #define STMT(type, base) \ 250 case Stmt::type##Class: \ 251 return getSourceRangeImpl<type>(this, &type::getSourceRange); 252 #include "clang/AST/StmtNodes.inc" 253 } 254 llvm_unreachable("unknown statement kind!"); 255 } 256 257 SourceLocation Stmt::getLocStart() const { 258 // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; 259 switch (getStmtClass()) { 260 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 261 #define ABSTRACT_STMT(type) 262 #define STMT(type, base) \ 263 case Stmt::type##Class: \ 264 return static_cast<const type*>(this)->getLocStart(); 265 #include "clang/AST/StmtNodes.inc" 266 } 267 llvm_unreachable("unknown statement kind"); 268 } 269 270 SourceLocation Stmt::getLocEnd() const { 271 switch (getStmtClass()) { 272 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 273 #define ABSTRACT_STMT(type) 274 #define STMT(type, base) \ 275 case Stmt::type##Class: \ 276 return static_cast<const type*>(this)->getLocEnd(); 277 #include "clang/AST/StmtNodes.inc" 278 } 279 llvm_unreachable("unknown statement kind"); 280 } 281 282 CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, 283 SourceLocation LB, SourceLocation RB) 284 : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) { 285 CompoundStmtBits.NumStmts = Stmts.size(); 286 assert(CompoundStmtBits.NumStmts == Stmts.size() && 287 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); 288 289 if (Stmts.size() == 0) { 290 Body = nullptr; 291 return; 292 } 293 294 Body = new (C) Stmt*[Stmts.size()]; 295 std::copy(Stmts.begin(), Stmts.end(), Body); 296 } 297 298 void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, 299 unsigned NumStmts) { 300 if (this->Body) 301 C.Deallocate(Body); 302 this->CompoundStmtBits.NumStmts = NumStmts; 303 304 Body = new (C) Stmt*[NumStmts]; 305 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); 306 } 307 308 const char *LabelStmt::getName() const { 309 return getDecl()->getIdentifier()->getNameStart(); 310 } 311 312 AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, 313 ArrayRef<const Attr*> Attrs, 314 Stmt *SubStmt) { 315 assert(!Attrs.empty() && "Attrs should not be empty"); 316 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), 317 llvm::alignOf<AttributedStmt>()); 318 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); 319 } 320 321 AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, 322 unsigned NumAttrs) { 323 assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); 324 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, 325 llvm::alignOf<AttributedStmt>()); 326 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); 327 } 328 329 std::string AsmStmt::generateAsmString(const ASTContext &C) const { 330 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 331 return gccAsmStmt->generateAsmString(C); 332 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 333 return msAsmStmt->generateAsmString(C); 334 llvm_unreachable("unknown asm statement kind!"); 335 } 336 337 StringRef AsmStmt::getOutputConstraint(unsigned i) const { 338 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 339 return gccAsmStmt->getOutputConstraint(i); 340 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 341 return msAsmStmt->getOutputConstraint(i); 342 llvm_unreachable("unknown asm statement kind!"); 343 } 344 345 const Expr *AsmStmt::getOutputExpr(unsigned i) const { 346 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 347 return gccAsmStmt->getOutputExpr(i); 348 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 349 return msAsmStmt->getOutputExpr(i); 350 llvm_unreachable("unknown asm statement kind!"); 351 } 352 353 StringRef AsmStmt::getInputConstraint(unsigned i) const { 354 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 355 return gccAsmStmt->getInputConstraint(i); 356 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 357 return msAsmStmt->getInputConstraint(i); 358 llvm_unreachable("unknown asm statement kind!"); 359 } 360 361 const Expr *AsmStmt::getInputExpr(unsigned i) const { 362 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 363 return gccAsmStmt->getInputExpr(i); 364 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 365 return msAsmStmt->getInputExpr(i); 366 llvm_unreachable("unknown asm statement kind!"); 367 } 368 369 StringRef AsmStmt::getClobber(unsigned i) const { 370 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 371 return gccAsmStmt->getClobber(i); 372 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 373 return msAsmStmt->getClobber(i); 374 llvm_unreachable("unknown asm statement kind!"); 375 } 376 377 /// getNumPlusOperands - Return the number of output operands that have a "+" 378 /// constraint. 379 unsigned AsmStmt::getNumPlusOperands() const { 380 unsigned Res = 0; 381 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) 382 if (isOutputPlusConstraint(i)) 383 ++Res; 384 return Res; 385 } 386 387 char GCCAsmStmt::AsmStringPiece::getModifier() const { 388 assert(isOperand() && "Only Operands can have modifiers."); 389 return isLetter(Str[0]) ? Str[0] : '\0'; 390 } 391 392 StringRef GCCAsmStmt::getClobber(unsigned i) const { 393 return getClobberStringLiteral(i)->getString(); 394 } 395 396 Expr *GCCAsmStmt::getOutputExpr(unsigned i) { 397 return cast<Expr>(Exprs[i]); 398 } 399 400 /// getOutputConstraint - Return the constraint string for the specified 401 /// output operand. All output constraints are known to be non-empty (either 402 /// '=' or '+'). 403 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { 404 return getOutputConstraintLiteral(i)->getString(); 405 } 406 407 Expr *GCCAsmStmt::getInputExpr(unsigned i) { 408 return cast<Expr>(Exprs[i + NumOutputs]); 409 } 410 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { 411 Exprs[i + NumOutputs] = E; 412 } 413 414 /// getInputConstraint - Return the specified input constraint. Unlike output 415 /// constraints, these can be empty. 416 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { 417 return getInputConstraintLiteral(i)->getString(); 418 } 419 420 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, 421 IdentifierInfo **Names, 422 StringLiteral **Constraints, 423 Stmt **Exprs, 424 unsigned NumOutputs, 425 unsigned NumInputs, 426 StringLiteral **Clobbers, 427 unsigned NumClobbers) { 428 this->NumOutputs = NumOutputs; 429 this->NumInputs = NumInputs; 430 this->NumClobbers = NumClobbers; 431 432 unsigned NumExprs = NumOutputs + NumInputs; 433 434 C.Deallocate(this->Names); 435 this->Names = new (C) IdentifierInfo*[NumExprs]; 436 std::copy(Names, Names + NumExprs, this->Names); 437 438 C.Deallocate(this->Exprs); 439 this->Exprs = new (C) Stmt*[NumExprs]; 440 std::copy(Exprs, Exprs + NumExprs, this->Exprs); 441 442 C.Deallocate(this->Constraints); 443 this->Constraints = new (C) StringLiteral*[NumExprs]; 444 std::copy(Constraints, Constraints + NumExprs, this->Constraints); 445 446 C.Deallocate(this->Clobbers); 447 this->Clobbers = new (C) StringLiteral*[NumClobbers]; 448 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); 449 } 450 451 /// getNamedOperand - Given a symbolic operand reference like %[foo], 452 /// translate this into a numeric value needed to reference the same operand. 453 /// This returns -1 if the operand name is invalid. 454 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { 455 unsigned NumPlusOperands = 0; 456 457 // Check if this is an output operand. 458 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { 459 if (getOutputName(i) == SymbolicName) 460 return i; 461 } 462 463 for (unsigned i = 0, e = getNumInputs(); i != e; ++i) 464 if (getInputName(i) == SymbolicName) 465 return getNumOutputs() + NumPlusOperands + i; 466 467 // Not found. 468 return -1; 469 } 470 471 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 472 /// it into pieces. If the asm string is erroneous, emit errors and return 473 /// true, otherwise return false. 474 unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, 475 const ASTContext &C, unsigned &DiagOffs) const { 476 StringRef Str = getAsmString()->getString(); 477 const char *StrStart = Str.begin(); 478 const char *StrEnd = Str.end(); 479 const char *CurPtr = StrStart; 480 481 // "Simple" inline asms have no constraints or operands, just convert the asm 482 // string to escape $'s. 483 if (isSimple()) { 484 std::string Result; 485 for (; CurPtr != StrEnd; ++CurPtr) { 486 switch (*CurPtr) { 487 case '$': 488 Result += "$$"; 489 break; 490 default: 491 Result += *CurPtr; 492 break; 493 } 494 } 495 Pieces.push_back(AsmStringPiece(Result)); 496 return 0; 497 } 498 499 // CurStringPiece - The current string that we are building up as we scan the 500 // asm string. 501 std::string CurStringPiece; 502 503 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); 504 505 while (1) { 506 // Done with the string? 507 if (CurPtr == StrEnd) { 508 if (!CurStringPiece.empty()) 509 Pieces.push_back(AsmStringPiece(CurStringPiece)); 510 return 0; 511 } 512 513 char CurChar = *CurPtr++; 514 switch (CurChar) { 515 case '$': CurStringPiece += "$$"; continue; 516 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; 517 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; 518 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; 519 case '%': 520 break; 521 default: 522 CurStringPiece += CurChar; 523 continue; 524 } 525 526 // Escaped "%" character in asm string. 527 if (CurPtr == StrEnd) { 528 // % at end of string is invalid (no escape). 529 DiagOffs = CurPtr-StrStart-1; 530 return diag::err_asm_invalid_escape; 531 } 532 533 char EscapedChar = *CurPtr++; 534 if (EscapedChar == '%') { // %% -> % 535 // Escaped percentage sign. 536 CurStringPiece += '%'; 537 continue; 538 } 539 540 if (EscapedChar == '=') { // %= -> Generate an unique ID. 541 CurStringPiece += "${:uid}"; 542 continue; 543 } 544 545 // Otherwise, we have an operand. If we have accumulated a string so far, 546 // add it to the Pieces list. 547 if (!CurStringPiece.empty()) { 548 Pieces.push_back(AsmStringPiece(CurStringPiece)); 549 CurStringPiece.clear(); 550 } 551 552 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that 553 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier. 554 555 const char *Begin = CurPtr - 1; // Points to the character following '%'. 556 const char *Percent = Begin - 1; // Points to '%'. 557 558 if (isLetter(EscapedChar)) { 559 if (CurPtr == StrEnd) { // Premature end. 560 DiagOffs = CurPtr-StrStart-1; 561 return diag::err_asm_invalid_escape; 562 } 563 EscapedChar = *CurPtr++; 564 } 565 566 const TargetInfo &TI = C.getTargetInfo(); 567 const SourceManager &SM = C.getSourceManager(); 568 const LangOptions &LO = C.getLangOpts(); 569 570 // Handle operands that don't have asmSymbolicName (e.g., %x4). 571 if (isDigit(EscapedChar)) { 572 // %n - Assembler operand n 573 unsigned N = 0; 574 575 --CurPtr; 576 while (CurPtr != StrEnd && isDigit(*CurPtr)) 577 N = N*10 + ((*CurPtr++)-'0'); 578 579 unsigned NumOperands = 580 getNumOutputs() + getNumPlusOperands() + getNumInputs(); 581 if (N >= NumOperands) { 582 DiagOffs = CurPtr-StrStart-1; 583 return diag::err_asm_invalid_operand_number; 584 } 585 586 // Str contains "x4" (Operand without the leading %). 587 std::string Str(Begin, CurPtr - Begin); 588 589 // (BeginLoc, EndLoc) represents the range of the operand we are currently 590 // processing. Unlike Str, the range includes the leading '%'. 591 SourceLocation BeginLoc = 592 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); 593 SourceLocation EndLoc = 594 getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI); 595 596 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); 597 continue; 598 } 599 600 // Handle operands that have asmSymbolicName (e.g., %x[foo]). 601 if (EscapedChar == '[') { 602 DiagOffs = CurPtr-StrStart-1; 603 604 // Find the ']'. 605 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); 606 if (NameEnd == nullptr) 607 return diag::err_asm_unterminated_symbolic_operand_name; 608 if (NameEnd == CurPtr) 609 return diag::err_asm_empty_symbolic_operand_name; 610 611 StringRef SymbolicName(CurPtr, NameEnd - CurPtr); 612 613 int N = getNamedOperand(SymbolicName); 614 if (N == -1) { 615 // Verify that an operand with that name exists. 616 DiagOffs = CurPtr-StrStart; 617 return diag::err_asm_unknown_symbolic_operand_name; 618 } 619 620 // Str contains "x[foo]" (Operand without the leading %). 621 std::string Str(Begin, NameEnd + 1 - Begin); 622 623 // (BeginLoc, EndLoc) represents the range of the operand we are currently 624 // processing. Unlike Str, the range includes the leading '%'. 625 SourceLocation BeginLoc = 626 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); 627 SourceLocation EndLoc = 628 getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI); 629 630 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); 631 632 CurPtr = NameEnd+1; 633 continue; 634 } 635 636 DiagOffs = CurPtr-StrStart-1; 637 return diag::err_asm_invalid_escape; 638 } 639 } 640 641 /// Assemble final IR asm string (GCC-style). 642 std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { 643 // Analyze the asm string to decompose it into its pieces. We know that Sema 644 // has already done this, so it is guaranteed to be successful. 645 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; 646 unsigned DiagOffs; 647 AnalyzeAsmString(Pieces, C, DiagOffs); 648 649 std::string AsmString; 650 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { 651 if (Pieces[i].isString()) 652 AsmString += Pieces[i].getString(); 653 else if (Pieces[i].getModifier() == '\0') 654 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); 655 else 656 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + 657 Pieces[i].getModifier() + '}'; 658 } 659 return AsmString; 660 } 661 662 /// Assemble final IR asm string (MS-style). 663 std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { 664 // FIXME: This needs to be translated into the IR string representation. 665 return AsmStr; 666 } 667 668 Expr *MSAsmStmt::getOutputExpr(unsigned i) { 669 return cast<Expr>(Exprs[i]); 670 } 671 672 Expr *MSAsmStmt::getInputExpr(unsigned i) { 673 return cast<Expr>(Exprs[i + NumOutputs]); 674 } 675 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { 676 Exprs[i + NumOutputs] = E; 677 } 678 679 QualType CXXCatchStmt::getCaughtType() const { 680 if (ExceptionDecl) 681 return ExceptionDecl->getType(); 682 return QualType(); 683 } 684 685 //===----------------------------------------------------------------------===// 686 // Constructors 687 //===----------------------------------------------------------------------===// 688 689 GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, 690 bool issimple, bool isvolatile, unsigned numoutputs, 691 unsigned numinputs, IdentifierInfo **names, 692 StringLiteral **constraints, Expr **exprs, 693 StringLiteral *asmstr, unsigned numclobbers, 694 StringLiteral **clobbers, SourceLocation rparenloc) 695 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, 696 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { 697 698 unsigned NumExprs = NumOutputs + NumInputs; 699 700 Names = new (C) IdentifierInfo*[NumExprs]; 701 std::copy(names, names + NumExprs, Names); 702 703 Exprs = new (C) Stmt*[NumExprs]; 704 std::copy(exprs, exprs + NumExprs, Exprs); 705 706 Constraints = new (C) StringLiteral*[NumExprs]; 707 std::copy(constraints, constraints + NumExprs, Constraints); 708 709 Clobbers = new (C) StringLiteral*[NumClobbers]; 710 std::copy(clobbers, clobbers + NumClobbers, Clobbers); 711 } 712 713 MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, 714 SourceLocation lbraceloc, bool issimple, bool isvolatile, 715 ArrayRef<Token> asmtoks, unsigned numoutputs, 716 unsigned numinputs, 717 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, 718 StringRef asmstr, ArrayRef<StringRef> clobbers, 719 SourceLocation endloc) 720 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, 721 numinputs, clobbers.size()), LBraceLoc(lbraceloc), 722 EndLoc(endloc), NumAsmToks(asmtoks.size()) { 723 724 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); 725 } 726 727 static StringRef copyIntoContext(const ASTContext &C, StringRef str) { 728 return str.copy(C); 729 } 730 731 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, 732 ArrayRef<Token> asmtoks, 733 ArrayRef<StringRef> constraints, 734 ArrayRef<Expr*> exprs, 735 ArrayRef<StringRef> clobbers) { 736 assert(NumAsmToks == asmtoks.size()); 737 assert(NumClobbers == clobbers.size()); 738 739 unsigned NumExprs = exprs.size(); 740 assert(NumExprs == NumOutputs + NumInputs); 741 assert(NumExprs == constraints.size()); 742 743 AsmStr = copyIntoContext(C, asmstr); 744 745 Exprs = new (C) Stmt*[NumExprs]; 746 for (unsigned i = 0, e = NumExprs; i != e; ++i) 747 Exprs[i] = exprs[i]; 748 749 AsmToks = new (C) Token[NumAsmToks]; 750 for (unsigned i = 0, e = NumAsmToks; i != e; ++i) 751 AsmToks[i] = asmtoks[i]; 752 753 Constraints = new (C) StringRef[NumExprs]; 754 for (unsigned i = 0, e = NumExprs; i != e; ++i) { 755 Constraints[i] = copyIntoContext(C, constraints[i]); 756 } 757 758 Clobbers = new (C) StringRef[NumClobbers]; 759 for (unsigned i = 0, e = NumClobbers; i != e; ++i) { 760 // FIXME: Avoid the allocation/copy if at all possible. 761 Clobbers[i] = copyIntoContext(C, clobbers[i]); 762 } 763 } 764 765 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, 766 Stmt *Body, SourceLocation FCL, 767 SourceLocation RPL) 768 : Stmt(ObjCForCollectionStmtClass) { 769 SubExprs[ELEM] = Elem; 770 SubExprs[COLLECTION] = Collect; 771 SubExprs[BODY] = Body; 772 ForLoc = FCL; 773 RParenLoc = RPL; 774 } 775 776 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, 777 Stmt **CatchStmts, unsigned NumCatchStmts, 778 Stmt *atFinallyStmt) 779 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), 780 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { 781 Stmt **Stmts = getStmts(); 782 Stmts[0] = atTryStmt; 783 for (unsigned I = 0; I != NumCatchStmts; ++I) 784 Stmts[I + 1] = CatchStmts[I]; 785 786 if (HasFinally) 787 Stmts[NumCatchStmts + 1] = atFinallyStmt; 788 } 789 790 ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, 791 SourceLocation atTryLoc, 792 Stmt *atTryStmt, 793 Stmt **CatchStmts, 794 unsigned NumCatchStmts, 795 Stmt *atFinallyStmt) { 796 unsigned Size = sizeof(ObjCAtTryStmt) + 797 (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); 798 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); 799 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, 800 atFinallyStmt); 801 } 802 803 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, 804 unsigned NumCatchStmts, 805 bool HasFinally) { 806 unsigned Size = sizeof(ObjCAtTryStmt) + 807 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); 808 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); 809 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); 810 } 811 812 SourceLocation ObjCAtTryStmt::getLocEnd() const { 813 if (HasFinally) 814 return getFinallyStmt()->getLocEnd(); 815 if (NumCatchStmts) 816 return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); 817 return getTryBody()->getLocEnd(); 818 } 819 820 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, 821 Stmt *tryBlock, ArrayRef<Stmt*> handlers) { 822 std::size_t Size = sizeof(CXXTryStmt); 823 Size += ((handlers.size() + 1) * sizeof(Stmt *)); 824 825 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); 826 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); 827 } 828 829 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, 830 unsigned numHandlers) { 831 std::size_t Size = sizeof(CXXTryStmt); 832 Size += ((numHandlers + 1) * sizeof(Stmt *)); 833 834 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); 835 return new (Mem) CXXTryStmt(Empty, numHandlers); 836 } 837 838 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, 839 ArrayRef<Stmt*> handlers) 840 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { 841 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); 842 Stmts[0] = tryBlock; 843 std::copy(handlers.begin(), handlers.end(), Stmts + 1); 844 } 845 846 CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, 847 Expr *Cond, Expr *Inc, DeclStmt *LoopVar, 848 Stmt *Body, SourceLocation FL, 849 SourceLocation CL, SourceLocation RPL) 850 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { 851 SubExprs[RANGE] = Range; 852 SubExprs[BEGINEND] = BeginEndStmt; 853 SubExprs[COND] = Cond; 854 SubExprs[INC] = Inc; 855 SubExprs[LOOPVAR] = LoopVar; 856 SubExprs[BODY] = Body; 857 } 858 859 Expr *CXXForRangeStmt::getRangeInit() { 860 DeclStmt *RangeStmt = getRangeStmt(); 861 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); 862 assert(RangeDecl && "for-range should have a single var decl"); 863 return RangeDecl->getInit(); 864 } 865 866 const Expr *CXXForRangeStmt::getRangeInit() const { 867 return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); 868 } 869 870 VarDecl *CXXForRangeStmt::getLoopVariable() { 871 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); 872 assert(LV && "No loop variable in CXXForRangeStmt"); 873 return cast<VarDecl>(LV); 874 } 875 876 const VarDecl *CXXForRangeStmt::getLoopVariable() const { 877 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); 878 } 879 880 IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 881 Stmt *then, SourceLocation EL, Stmt *elsev) 882 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) 883 { 884 setConditionVariable(C, var); 885 SubExprs[COND] = cond; 886 SubExprs[THEN] = then; 887 SubExprs[ELSE] = elsev; 888 } 889 890 VarDecl *IfStmt::getConditionVariable() const { 891 if (!SubExprs[VAR]) 892 return nullptr; 893 894 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 895 return cast<VarDecl>(DS->getSingleDecl()); 896 } 897 898 void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 899 if (!V) { 900 SubExprs[VAR] = nullptr; 901 return; 902 } 903 904 SourceRange VarRange = V->getSourceRange(); 905 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 906 VarRange.getEnd()); 907 } 908 909 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, 910 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, 911 SourceLocation RP) 912 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) 913 { 914 SubExprs[INIT] = Init; 915 setConditionVariable(C, condVar); 916 SubExprs[COND] = Cond; 917 SubExprs[INC] = Inc; 918 SubExprs[BODY] = Body; 919 } 920 921 VarDecl *ForStmt::getConditionVariable() const { 922 if (!SubExprs[CONDVAR]) 923 return nullptr; 924 925 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); 926 return cast<VarDecl>(DS->getSingleDecl()); 927 } 928 929 void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 930 if (!V) { 931 SubExprs[CONDVAR] = nullptr; 932 return; 933 } 934 935 SourceRange VarRange = V->getSourceRange(); 936 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 937 VarRange.getEnd()); 938 } 939 940 SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) 941 : Stmt(SwitchStmtClass), FirstCase(nullptr, false) { 942 setConditionVariable(C, Var); 943 SubExprs[COND] = cond; 944 SubExprs[BODY] = nullptr; 945 } 946 947 VarDecl *SwitchStmt::getConditionVariable() const { 948 if (!SubExprs[VAR]) 949 return nullptr; 950 951 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 952 return cast<VarDecl>(DS->getSingleDecl()); 953 } 954 955 void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 956 if (!V) { 957 SubExprs[VAR] = nullptr; 958 return; 959 } 960 961 SourceRange VarRange = V->getSourceRange(); 962 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 963 VarRange.getEnd()); 964 } 965 966 Stmt *SwitchCase::getSubStmt() { 967 if (isa<CaseStmt>(this)) 968 return cast<CaseStmt>(this)->getSubStmt(); 969 return cast<DefaultStmt>(this)->getSubStmt(); 970 } 971 972 WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 973 SourceLocation WL) 974 : Stmt(WhileStmtClass) { 975 setConditionVariable(C, Var); 976 SubExprs[COND] = cond; 977 SubExprs[BODY] = body; 978 WhileLoc = WL; 979 } 980 981 VarDecl *WhileStmt::getConditionVariable() const { 982 if (!SubExprs[VAR]) 983 return nullptr; 984 985 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 986 return cast<VarDecl>(DS->getSingleDecl()); 987 } 988 989 void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 990 if (!V) { 991 SubExprs[VAR] = nullptr; 992 return; 993 } 994 995 SourceRange VarRange = V->getSourceRange(); 996 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 997 VarRange.getEnd()); 998 } 999 1000 // IndirectGotoStmt 1001 LabelDecl *IndirectGotoStmt::getConstantTarget() { 1002 if (AddrLabelExpr *E = 1003 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) 1004 return E->getLabel(); 1005 return nullptr; 1006 } 1007 1008 // ReturnStmt 1009 const Expr* ReturnStmt::getRetValue() const { 1010 return cast_or_null<Expr>(RetExpr); 1011 } 1012 Expr* ReturnStmt::getRetValue() { 1013 return cast_or_null<Expr>(RetExpr); 1014 } 1015 1016 SEHTryStmt::SEHTryStmt(bool IsCXXTry, 1017 SourceLocation TryLoc, 1018 Stmt *TryBlock, 1019 Stmt *Handler) 1020 : Stmt(SEHTryStmtClass), 1021 IsCXXTry(IsCXXTry), 1022 TryLoc(TryLoc) 1023 { 1024 Children[TRY] = TryBlock; 1025 Children[HANDLER] = Handler; 1026 } 1027 1028 SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, 1029 SourceLocation TryLoc, Stmt *TryBlock, 1030 Stmt *Handler) { 1031 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); 1032 } 1033 1034 SEHExceptStmt* SEHTryStmt::getExceptHandler() const { 1035 return dyn_cast<SEHExceptStmt>(getHandler()); 1036 } 1037 1038 SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { 1039 return dyn_cast<SEHFinallyStmt>(getHandler()); 1040 } 1041 1042 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, 1043 Expr *FilterExpr, 1044 Stmt *Block) 1045 : Stmt(SEHExceptStmtClass), 1046 Loc(Loc) 1047 { 1048 Children[FILTER_EXPR] = FilterExpr; 1049 Children[BLOCK] = Block; 1050 } 1051 1052 SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, 1053 Expr *FilterExpr, Stmt *Block) { 1054 return new(C) SEHExceptStmt(Loc,FilterExpr,Block); 1055 } 1056 1057 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, 1058 Stmt *Block) 1059 : Stmt(SEHFinallyStmtClass), 1060 Loc(Loc), 1061 Block(Block) 1062 {} 1063 1064 SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, 1065 Stmt *Block) { 1066 return new(C)SEHFinallyStmt(Loc,Block); 1067 } 1068 1069 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { 1070 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); 1071 1072 // Offset of the first Capture object. 1073 unsigned FirstCaptureOffset = 1074 llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1075 1076 return reinterpret_cast<Capture *>( 1077 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) 1078 + FirstCaptureOffset); 1079 } 1080 1081 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, 1082 ArrayRef<Capture> Captures, 1083 ArrayRef<Expr *> CaptureInits, 1084 CapturedDecl *CD, 1085 RecordDecl *RD) 1086 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), 1087 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { 1088 assert( S && "null captured statement"); 1089 assert(CD && "null captured declaration for captured statement"); 1090 assert(RD && "null record declaration for captured statement"); 1091 1092 // Copy initialization expressions. 1093 Stmt **Stored = getStoredStmts(); 1094 for (unsigned I = 0, N = NumCaptures; I != N; ++I) 1095 *Stored++ = CaptureInits[I]; 1096 1097 // Copy the statement being captured. 1098 *Stored = S; 1099 1100 // Copy all Capture objects. 1101 Capture *Buffer = getStoredCaptures(); 1102 std::copy(Captures.begin(), Captures.end(), Buffer); 1103 } 1104 1105 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) 1106 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), 1107 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { 1108 getStoredStmts()[NumCaptures] = nullptr; 1109 } 1110 1111 CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, 1112 CapturedRegionKind Kind, 1113 ArrayRef<Capture> Captures, 1114 ArrayRef<Expr *> CaptureInits, 1115 CapturedDecl *CD, 1116 RecordDecl *RD) { 1117 // The layout is 1118 // 1119 // ----------------------------------------------------------- 1120 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | 1121 // ----------------^-------------------^---------------------- 1122 // getStoredStmts() getStoredCaptures() 1123 // 1124 // where S is the statement being captured. 1125 // 1126 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); 1127 1128 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); 1129 if (!Captures.empty()) { 1130 // Realign for the following Capture array. 1131 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1132 Size += sizeof(Capture) * Captures.size(); 1133 } 1134 1135 void *Mem = Context.Allocate(Size); 1136 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); 1137 } 1138 1139 CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, 1140 unsigned NumCaptures) { 1141 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); 1142 if (NumCaptures > 0) { 1143 // Realign for the following Capture array. 1144 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1145 Size += sizeof(Capture) * NumCaptures; 1146 } 1147 1148 void *Mem = Context.Allocate(Size); 1149 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); 1150 } 1151 1152 Stmt::child_range CapturedStmt::children() { 1153 // Children are captured field initilizers. 1154 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); 1155 } 1156 1157 bool CapturedStmt::capturesVariable(const VarDecl *Var) const { 1158 for (const auto &I : captures()) { 1159 if (!I.capturesVariable()) 1160 continue; 1161 1162 // This does not handle variable redeclarations. This should be 1163 // extended to capture variables with redeclarations, for example 1164 // a thread-private variable in OpenMP. 1165 if (I.getCapturedVar() == Var) 1166 return true; 1167 } 1168 1169 return false; 1170 } 1171 1172 OMPClause::child_range OMPClause::children() { 1173 switch(getClauseKind()) { 1174 default : break; 1175 #define OPENMP_CLAUSE(Name, Class) \ 1176 case OMPC_ ## Name : return static_cast<Class *>(this)->children(); 1177 #include "clang/Basic/OpenMPKinds.def" 1178 } 1179 llvm_unreachable("unknown OMPClause"); 1180 } 1181 1182 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 1183 assert(VL.size() == varlist_size() && 1184 "Number of private copies is not the same as the preallocated buffer"); 1185 std::copy(VL.begin(), VL.end(), varlist_end()); 1186 } 1187 1188 OMPPrivateClause * 1189 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 1190 SourceLocation LParenLoc, SourceLocation EndLoc, 1191 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { 1192 // Allocate space for private variables and initializer expressions. 1193 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), 1194 llvm::alignOf<Expr *>()) + 1195 2 * sizeof(Expr *) * VL.size()); 1196 OMPPrivateClause *Clause = 1197 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1198 Clause->setVarRefs(VL); 1199 Clause->setPrivateCopies(PrivateVL); 1200 return Clause; 1201 } 1202 1203 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, 1204 unsigned N) { 1205 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), 1206 llvm::alignOf<Expr *>()) + 1207 2 * sizeof(Expr *) * N); 1208 return new (Mem) OMPPrivateClause(N); 1209 } 1210 1211 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 1212 assert(VL.size() == varlist_size() && 1213 "Number of private copies is not the same as the preallocated buffer"); 1214 std::copy(VL.begin(), VL.end(), varlist_end()); 1215 } 1216 1217 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { 1218 assert(VL.size() == varlist_size() && 1219 "Number of inits is not the same as the preallocated buffer"); 1220 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 1221 } 1222 1223 OMPFirstprivateClause * 1224 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 1225 SourceLocation LParenLoc, SourceLocation EndLoc, 1226 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 1227 ArrayRef<Expr *> InitVL) { 1228 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), 1229 llvm::alignOf<Expr *>()) + 1230 3 * sizeof(Expr *) * VL.size()); 1231 OMPFirstprivateClause *Clause = 1232 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1233 Clause->setVarRefs(VL); 1234 Clause->setPrivateCopies(PrivateVL); 1235 Clause->setInits(InitVL); 1236 return Clause; 1237 } 1238 1239 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, 1240 unsigned N) { 1241 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), 1242 llvm::alignOf<Expr *>()) + 1243 3 * sizeof(Expr *) * N); 1244 return new (Mem) OMPFirstprivateClause(N); 1245 } 1246 1247 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { 1248 assert(PrivateCopies.size() == varlist_size() && 1249 "Number of private copies is not the same as the preallocated buffer"); 1250 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); 1251 } 1252 1253 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 1254 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 1255 "not the same as the " 1256 "preallocated buffer"); 1257 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); 1258 } 1259 1260 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 1261 assert(DstExprs.size() == varlist_size() && "Number of destination " 1262 "expressions is not the same as " 1263 "the preallocated buffer"); 1264 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 1265 } 1266 1267 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 1268 assert(AssignmentOps.size() == varlist_size() && 1269 "Number of assignment expressions is not the same as the preallocated " 1270 "buffer"); 1271 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 1272 getDestinationExprs().end()); 1273 } 1274 1275 OMPLastprivateClause *OMPLastprivateClause::Create( 1276 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1277 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 1278 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 1279 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), 1280 llvm::alignOf<Expr *>()) + 1281 5 * sizeof(Expr *) * VL.size()); 1282 OMPLastprivateClause *Clause = 1283 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1284 Clause->setVarRefs(VL); 1285 Clause->setSourceExprs(SrcExprs); 1286 Clause->setDestinationExprs(DstExprs); 1287 Clause->setAssignmentOps(AssignmentOps); 1288 return Clause; 1289 } 1290 1291 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, 1292 unsigned N) { 1293 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), 1294 llvm::alignOf<Expr *>()) + 1295 5 * sizeof(Expr *) * N); 1296 return new (Mem) OMPLastprivateClause(N); 1297 } 1298 1299 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, 1300 SourceLocation StartLoc, 1301 SourceLocation LParenLoc, 1302 SourceLocation EndLoc, 1303 ArrayRef<Expr *> VL) { 1304 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), 1305 llvm::alignOf<Expr *>()) + 1306 sizeof(Expr *) * VL.size()); 1307 OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, 1308 EndLoc, VL.size()); 1309 Clause->setVarRefs(VL); 1310 return Clause; 1311 } 1312 1313 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, 1314 unsigned N) { 1315 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), 1316 llvm::alignOf<Expr *>()) + 1317 sizeof(Expr *) * N); 1318 return new (Mem) OMPSharedClause(N); 1319 } 1320 1321 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { 1322 assert(PL.size() == varlist_size() && 1323 "Number of privates is not the same as the preallocated buffer"); 1324 std::copy(PL.begin(), PL.end(), varlist_end()); 1325 } 1326 1327 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { 1328 assert(IL.size() == varlist_size() && 1329 "Number of inits is not the same as the preallocated buffer"); 1330 std::copy(IL.begin(), IL.end(), getPrivates().end()); 1331 } 1332 1333 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { 1334 assert(UL.size() == varlist_size() && 1335 "Number of updates is not the same as the preallocated buffer"); 1336 std::copy(UL.begin(), UL.end(), getInits().end()); 1337 } 1338 1339 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { 1340 assert(FL.size() == varlist_size() && 1341 "Number of final updates is not the same as the preallocated buffer"); 1342 std::copy(FL.begin(), FL.end(), getUpdates().end()); 1343 } 1344 1345 OMPLinearClause *OMPLinearClause::Create( 1346 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1347 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 1348 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 1349 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) { 1350 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions 1351 // (Step and CalcStep). 1352 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), 1353 llvm::alignOf<Expr *>()) + 1354 (5 * VL.size() + 2) * sizeof(Expr *)); 1355 OMPLinearClause *Clause = new (Mem) OMPLinearClause( 1356 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); 1357 Clause->setVarRefs(VL); 1358 Clause->setPrivates(PL); 1359 Clause->setInits(IL); 1360 // Fill update and final expressions with zeroes, they are provided later, 1361 // after the directive construction. 1362 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), 1363 nullptr); 1364 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), 1365 nullptr); 1366 Clause->setStep(Step); 1367 Clause->setCalcStep(CalcStep); 1368 return Clause; 1369 } 1370 1371 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, 1372 unsigned NumVars) { 1373 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions 1374 // (Step and CalcStep). 1375 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), 1376 llvm::alignOf<Expr *>()) + 1377 (5 * NumVars + 2) * sizeof(Expr *)); 1378 return new (Mem) OMPLinearClause(NumVars); 1379 } 1380 1381 OMPAlignedClause * 1382 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, 1383 SourceLocation LParenLoc, SourceLocation ColonLoc, 1384 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { 1385 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), 1386 llvm::alignOf<Expr *>()) + 1387 sizeof(Expr *) * (VL.size() + 1)); 1388 OMPAlignedClause *Clause = new (Mem) 1389 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 1390 Clause->setVarRefs(VL); 1391 Clause->setAlignment(A); 1392 return Clause; 1393 } 1394 1395 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, 1396 unsigned NumVars) { 1397 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), 1398 llvm::alignOf<Expr *>()) + 1399 sizeof(Expr *) * (NumVars + 1)); 1400 return new (Mem) OMPAlignedClause(NumVars); 1401 } 1402 1403 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 1404 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 1405 "not the same as the " 1406 "preallocated buffer"); 1407 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 1408 } 1409 1410 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 1411 assert(DstExprs.size() == varlist_size() && "Number of destination " 1412 "expressions is not the same as " 1413 "the preallocated buffer"); 1414 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 1415 } 1416 1417 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 1418 assert(AssignmentOps.size() == varlist_size() && 1419 "Number of assignment expressions is not the same as the preallocated " 1420 "buffer"); 1421 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 1422 getDestinationExprs().end()); 1423 } 1424 1425 OMPCopyinClause *OMPCopyinClause::Create( 1426 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1427 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 1428 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 1429 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), 1430 llvm::alignOf<Expr *>()) + 1431 4 * sizeof(Expr *) * VL.size()); 1432 OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, 1433 EndLoc, VL.size()); 1434 Clause->setVarRefs(VL); 1435 Clause->setSourceExprs(SrcExprs); 1436 Clause->setDestinationExprs(DstExprs); 1437 Clause->setAssignmentOps(AssignmentOps); 1438 return Clause; 1439 } 1440 1441 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, 1442 unsigned N) { 1443 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), 1444 llvm::alignOf<Expr *>()) + 1445 4 * sizeof(Expr *) * N); 1446 return new (Mem) OMPCopyinClause(N); 1447 } 1448 1449 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 1450 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 1451 "not the same as the " 1452 "preallocated buffer"); 1453 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 1454 } 1455 1456 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 1457 assert(DstExprs.size() == varlist_size() && "Number of destination " 1458 "expressions is not the same as " 1459 "the preallocated buffer"); 1460 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 1461 } 1462 1463 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 1464 assert(AssignmentOps.size() == varlist_size() && 1465 "Number of assignment expressions is not the same as the preallocated " 1466 "buffer"); 1467 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 1468 getDestinationExprs().end()); 1469 } 1470 1471 OMPCopyprivateClause *OMPCopyprivateClause::Create( 1472 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1473 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 1474 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 1475 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), 1476 llvm::alignOf<Expr *>()) + 1477 4 * sizeof(Expr *) * VL.size()); 1478 OMPCopyprivateClause *Clause = 1479 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1480 Clause->setVarRefs(VL); 1481 Clause->setSourceExprs(SrcExprs); 1482 Clause->setDestinationExprs(DstExprs); 1483 Clause->setAssignmentOps(AssignmentOps); 1484 return Clause; 1485 } 1486 1487 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, 1488 unsigned N) { 1489 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), 1490 llvm::alignOf<Expr *>()) + 1491 4 * sizeof(Expr *) * N); 1492 return new (Mem) OMPCopyprivateClause(N); 1493 } 1494 1495 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { 1496 assert(Clauses.size() == getNumClauses() && 1497 "Number of clauses is not the same as the preallocated buffer"); 1498 std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); 1499 } 1500 1501 void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) { 1502 assert(A.size() == getCollapsedNumber() && 1503 "Number of loop counters is not the same as the collapsed number"); 1504 std::copy(A.begin(), A.end(), getCounters().begin()); 1505 } 1506 1507 void OMPLoopDirective::setPrivateCounters(ArrayRef<Expr *> A) { 1508 assert(A.size() == getCollapsedNumber() && "Number of loop private counters " 1509 "is not the same as the collapsed " 1510 "number"); 1511 std::copy(A.begin(), A.end(), getPrivateCounters().begin()); 1512 } 1513 1514 void OMPLoopDirective::setInits(ArrayRef<Expr *> A) { 1515 assert(A.size() == getCollapsedNumber() && 1516 "Number of counter inits is not the same as the collapsed number"); 1517 std::copy(A.begin(), A.end(), getInits().begin()); 1518 } 1519 1520 void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) { 1521 assert(A.size() == getCollapsedNumber() && 1522 "Number of counter updates is not the same as the collapsed number"); 1523 std::copy(A.begin(), A.end(), getUpdates().begin()); 1524 } 1525 1526 void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) { 1527 assert(A.size() == getCollapsedNumber() && 1528 "Number of counter finals is not the same as the collapsed number"); 1529 std::copy(A.begin(), A.end(), getFinals().begin()); 1530 } 1531 1532 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 1533 assert( 1534 LHSExprs.size() == varlist_size() && 1535 "Number of LHS expressions is not the same as the preallocated buffer"); 1536 std::copy(LHSExprs.begin(), LHSExprs.end(), varlist_end()); 1537 } 1538 1539 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 1540 assert( 1541 RHSExprs.size() == varlist_size() && 1542 "Number of RHS expressions is not the same as the preallocated buffer"); 1543 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 1544 } 1545 1546 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 1547 assert(ReductionOps.size() == varlist_size() && "Number of reduction " 1548 "expressions is not the same " 1549 "as the preallocated buffer"); 1550 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 1551 } 1552 1553 OMPReductionClause *OMPReductionClause::Create( 1554 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1555 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 1556 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 1557 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 1558 ArrayRef<Expr *> ReductionOps) { 1559 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), 1560 llvm::alignOf<Expr *>()) + 1561 4 * sizeof(Expr *) * VL.size()); 1562 OMPReductionClause *Clause = new (Mem) OMPReductionClause( 1563 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 1564 Clause->setVarRefs(VL); 1565 Clause->setLHSExprs(LHSExprs); 1566 Clause->setRHSExprs(RHSExprs); 1567 Clause->setReductionOps(ReductionOps); 1568 return Clause; 1569 } 1570 1571 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, 1572 unsigned N) { 1573 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), 1574 llvm::alignOf<Expr *>()) + 1575 4 * sizeof(Expr *) * N); 1576 return new (Mem) OMPReductionClause(N); 1577 } 1578 1579 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, 1580 SourceLocation StartLoc, 1581 SourceLocation LParenLoc, 1582 SourceLocation EndLoc, 1583 ArrayRef<Expr *> VL) { 1584 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), 1585 llvm::alignOf<Expr *>()) + 1586 sizeof(Expr *) * VL.size()); 1587 OMPFlushClause *Clause = 1588 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1589 Clause->setVarRefs(VL); 1590 return Clause; 1591 } 1592 1593 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { 1594 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), 1595 llvm::alignOf<Expr *>()) + 1596 sizeof(Expr *) * N); 1597 return new (Mem) OMPFlushClause(N); 1598 } 1599 1600 OMPDependClause * 1601 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, 1602 SourceLocation LParenLoc, SourceLocation EndLoc, 1603 OpenMPDependClauseKind DepKind, SourceLocation DepLoc, 1604 SourceLocation ColonLoc, ArrayRef<Expr *> VL) { 1605 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), 1606 llvm::alignOf<Expr *>()) + 1607 sizeof(Expr *) * VL.size()); 1608 OMPDependClause *Clause = 1609 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1610 Clause->setVarRefs(VL); 1611 Clause->setDependencyKind(DepKind); 1612 Clause->setDependencyLoc(DepLoc); 1613 Clause->setColonLoc(ColonLoc); 1614 return Clause; 1615 } 1616 1617 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) { 1618 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), 1619 llvm::alignOf<Expr *>()) + 1620 sizeof(Expr *) * N); 1621 return new (Mem) OMPDependClause(N); 1622 } 1623 1624 OMPParallelDirective *OMPParallelDirective::Create( 1625 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1626 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) { 1627 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), 1628 llvm::alignOf<OMPClause *>()); 1629 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1630 sizeof(Stmt *)); 1631 OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, 1632 Clauses.size()); 1633 Dir->setClauses(Clauses); 1634 Dir->setAssociatedStmt(AssociatedStmt); 1635 Dir->setHasCancel(HasCancel); 1636 return Dir; 1637 } 1638 1639 OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, 1640 unsigned NumClauses, 1641 EmptyShell) { 1642 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), 1643 llvm::alignOf<OMPClause *>()); 1644 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1645 sizeof(Stmt *)); 1646 return new (Mem) OMPParallelDirective(NumClauses); 1647 } 1648 1649 OMPSimdDirective * 1650 OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1651 SourceLocation EndLoc, unsigned CollapsedNum, 1652 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, 1653 const HelperExprs &Exprs) { 1654 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), 1655 llvm::alignOf<OMPClause *>()); 1656 void *Mem = 1657 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1658 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); 1659 OMPSimdDirective *Dir = new (Mem) 1660 OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1661 Dir->setClauses(Clauses); 1662 Dir->setAssociatedStmt(AssociatedStmt); 1663 Dir->setIterationVariable(Exprs.IterationVarRef); 1664 Dir->setLastIteration(Exprs.LastIteration); 1665 Dir->setCalcLastIteration(Exprs.CalcLastIteration); 1666 Dir->setPreCond(Exprs.PreCond); 1667 Dir->setCond(Exprs.Cond); 1668 Dir->setInit(Exprs.Init); 1669 Dir->setInc(Exprs.Inc); 1670 Dir->setCounters(Exprs.Counters); 1671 Dir->setPrivateCounters(Exprs.PrivateCounters); 1672 Dir->setInits(Exprs.Inits); 1673 Dir->setUpdates(Exprs.Updates); 1674 Dir->setFinals(Exprs.Finals); 1675 return Dir; 1676 } 1677 1678 OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, 1679 unsigned NumClauses, 1680 unsigned CollapsedNum, 1681 EmptyShell) { 1682 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), 1683 llvm::alignOf<OMPClause *>()); 1684 void *Mem = 1685 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1686 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); 1687 return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); 1688 } 1689 1690 OMPForDirective * 1691 OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1692 SourceLocation EndLoc, unsigned CollapsedNum, 1693 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, 1694 const HelperExprs &Exprs, bool HasCancel) { 1695 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), 1696 llvm::alignOf<OMPClause *>()); 1697 void *Mem = 1698 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1699 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); 1700 OMPForDirective *Dir = 1701 new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1702 Dir->setClauses(Clauses); 1703 Dir->setAssociatedStmt(AssociatedStmt); 1704 Dir->setIterationVariable(Exprs.IterationVarRef); 1705 Dir->setLastIteration(Exprs.LastIteration); 1706 Dir->setCalcLastIteration(Exprs.CalcLastIteration); 1707 Dir->setPreCond(Exprs.PreCond); 1708 Dir->setCond(Exprs.Cond); 1709 Dir->setInit(Exprs.Init); 1710 Dir->setInc(Exprs.Inc); 1711 Dir->setIsLastIterVariable(Exprs.IL); 1712 Dir->setLowerBoundVariable(Exprs.LB); 1713 Dir->setUpperBoundVariable(Exprs.UB); 1714 Dir->setStrideVariable(Exprs.ST); 1715 Dir->setEnsureUpperBound(Exprs.EUB); 1716 Dir->setNextLowerBound(Exprs.NLB); 1717 Dir->setNextUpperBound(Exprs.NUB); 1718 Dir->setCounters(Exprs.Counters); 1719 Dir->setPrivateCounters(Exprs.PrivateCounters); 1720 Dir->setInits(Exprs.Inits); 1721 Dir->setUpdates(Exprs.Updates); 1722 Dir->setFinals(Exprs.Finals); 1723 Dir->setHasCancel(HasCancel); 1724 return Dir; 1725 } 1726 1727 OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, 1728 unsigned NumClauses, 1729 unsigned CollapsedNum, 1730 EmptyShell) { 1731 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), 1732 llvm::alignOf<OMPClause *>()); 1733 void *Mem = 1734 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1735 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); 1736 return new (Mem) OMPForDirective(CollapsedNum, NumClauses); 1737 } 1738 1739 OMPForSimdDirective * 1740 OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1741 SourceLocation EndLoc, unsigned CollapsedNum, 1742 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, 1743 const HelperExprs &Exprs) { 1744 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), 1745 llvm::alignOf<OMPClause *>()); 1746 void *Mem = 1747 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1748 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); 1749 OMPForSimdDirective *Dir = new (Mem) 1750 OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1751 Dir->setClauses(Clauses); 1752 Dir->setAssociatedStmt(AssociatedStmt); 1753 Dir->setIterationVariable(Exprs.IterationVarRef); 1754 Dir->setLastIteration(Exprs.LastIteration); 1755 Dir->setCalcLastIteration(Exprs.CalcLastIteration); 1756 Dir->setPreCond(Exprs.PreCond); 1757 Dir->setCond(Exprs.Cond); 1758 Dir->setInit(Exprs.Init); 1759 Dir->setInc(Exprs.Inc); 1760 Dir->setIsLastIterVariable(Exprs.IL); 1761 Dir->setLowerBoundVariable(Exprs.LB); 1762 Dir->setUpperBoundVariable(Exprs.UB); 1763 Dir->setStrideVariable(Exprs.ST); 1764 Dir->setEnsureUpperBound(Exprs.EUB); 1765 Dir->setNextLowerBound(Exprs.NLB); 1766 Dir->setNextUpperBound(Exprs.NUB); 1767 Dir->setCounters(Exprs.Counters); 1768 Dir->setPrivateCounters(Exprs.PrivateCounters); 1769 Dir->setInits(Exprs.Inits); 1770 Dir->setUpdates(Exprs.Updates); 1771 Dir->setFinals(Exprs.Finals); 1772 return Dir; 1773 } 1774 1775 OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C, 1776 unsigned NumClauses, 1777 unsigned CollapsedNum, 1778 EmptyShell) { 1779 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), 1780 llvm::alignOf<OMPClause *>()); 1781 void *Mem = 1782 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1783 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); 1784 return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses); 1785 } 1786 1787 OMPSectionsDirective *OMPSectionsDirective::Create( 1788 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1789 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) { 1790 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), 1791 llvm::alignOf<OMPClause *>()); 1792 void *Mem = 1793 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1794 OMPSectionsDirective *Dir = 1795 new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); 1796 Dir->setClauses(Clauses); 1797 Dir->setAssociatedStmt(AssociatedStmt); 1798 Dir->setHasCancel(HasCancel); 1799 return Dir; 1800 } 1801 1802 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, 1803 unsigned NumClauses, 1804 EmptyShell) { 1805 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), 1806 llvm::alignOf<OMPClause *>()); 1807 void *Mem = 1808 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1809 return new (Mem) OMPSectionsDirective(NumClauses); 1810 } 1811 1812 OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, 1813 SourceLocation StartLoc, 1814 SourceLocation EndLoc, 1815 Stmt *AssociatedStmt, 1816 bool HasCancel) { 1817 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), 1818 llvm::alignOf<Stmt *>()); 1819 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1820 OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); 1821 Dir->setAssociatedStmt(AssociatedStmt); 1822 Dir->setHasCancel(HasCancel); 1823 return Dir; 1824 } 1825 1826 OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, 1827 EmptyShell) { 1828 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), 1829 llvm::alignOf<Stmt *>()); 1830 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1831 return new (Mem) OMPSectionDirective(); 1832 } 1833 1834 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, 1835 SourceLocation StartLoc, 1836 SourceLocation EndLoc, 1837 ArrayRef<OMPClause *> Clauses, 1838 Stmt *AssociatedStmt) { 1839 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), 1840 llvm::alignOf<OMPClause *>()); 1841 void *Mem = 1842 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1843 OMPSingleDirective *Dir = 1844 new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); 1845 Dir->setClauses(Clauses); 1846 Dir->setAssociatedStmt(AssociatedStmt); 1847 return Dir; 1848 } 1849 1850 OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, 1851 unsigned NumClauses, 1852 EmptyShell) { 1853 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), 1854 llvm::alignOf<OMPClause *>()); 1855 void *Mem = 1856 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1857 return new (Mem) OMPSingleDirective(NumClauses); 1858 } 1859 1860 OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, 1861 SourceLocation StartLoc, 1862 SourceLocation EndLoc, 1863 Stmt *AssociatedStmt) { 1864 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), 1865 llvm::alignOf<Stmt *>()); 1866 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1867 OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); 1868 Dir->setAssociatedStmt(AssociatedStmt); 1869 return Dir; 1870 } 1871 1872 OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, 1873 EmptyShell) { 1874 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), 1875 llvm::alignOf<Stmt *>()); 1876 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1877 return new (Mem) OMPMasterDirective(); 1878 } 1879 1880 OMPCriticalDirective *OMPCriticalDirective::Create( 1881 const ASTContext &C, const DeclarationNameInfo &Name, 1882 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { 1883 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), 1884 llvm::alignOf<Stmt *>()); 1885 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1886 OMPCriticalDirective *Dir = 1887 new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc); 1888 Dir->setAssociatedStmt(AssociatedStmt); 1889 return Dir; 1890 } 1891 1892 OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, 1893 EmptyShell) { 1894 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), 1895 llvm::alignOf<Stmt *>()); 1896 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1897 return new (Mem) OMPCriticalDirective(); 1898 } 1899 1900 OMPParallelForDirective *OMPParallelForDirective::Create( 1901 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1902 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, 1903 const HelperExprs &Exprs, bool HasCancel) { 1904 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), 1905 llvm::alignOf<OMPClause *>()); 1906 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1907 sizeof(Stmt *) * 1908 numLoopChildren(CollapsedNum, OMPD_parallel_for)); 1909 OMPParallelForDirective *Dir = new (Mem) 1910 OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1911 Dir->setClauses(Clauses); 1912 Dir->setAssociatedStmt(AssociatedStmt); 1913 Dir->setIterationVariable(Exprs.IterationVarRef); 1914 Dir->setLastIteration(Exprs.LastIteration); 1915 Dir->setCalcLastIteration(Exprs.CalcLastIteration); 1916 Dir->setPreCond(Exprs.PreCond); 1917 Dir->setCond(Exprs.Cond); 1918 Dir->setInit(Exprs.Init); 1919 Dir->setInc(Exprs.Inc); 1920 Dir->setIsLastIterVariable(Exprs.IL); 1921 Dir->setLowerBoundVariable(Exprs.LB); 1922 Dir->setUpperBoundVariable(Exprs.UB); 1923 Dir->setStrideVariable(Exprs.ST); 1924 Dir->setEnsureUpperBound(Exprs.EUB); 1925 Dir->setNextLowerBound(Exprs.NLB); 1926 Dir->setNextUpperBound(Exprs.NUB); 1927 Dir->setCounters(Exprs.Counters); 1928 Dir->setPrivateCounters(Exprs.PrivateCounters); 1929 Dir->setInits(Exprs.Inits); 1930 Dir->setUpdates(Exprs.Updates); 1931 Dir->setFinals(Exprs.Finals); 1932 Dir->setHasCancel(HasCancel); 1933 return Dir; 1934 } 1935 1936 OMPParallelForDirective * 1937 OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, 1938 unsigned CollapsedNum, EmptyShell) { 1939 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), 1940 llvm::alignOf<OMPClause *>()); 1941 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1942 sizeof(Stmt *) * 1943 numLoopChildren(CollapsedNum, OMPD_parallel_for)); 1944 return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); 1945 } 1946 1947 OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create( 1948 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1949 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, 1950 const HelperExprs &Exprs) { 1951 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), 1952 llvm::alignOf<OMPClause *>()); 1953 void *Mem = C.Allocate( 1954 Size + sizeof(OMPClause *) * Clauses.size() + 1955 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); 1956 OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( 1957 StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1958 Dir->setClauses(Clauses); 1959 Dir->setAssociatedStmt(AssociatedStmt); 1960 Dir->setIterationVariable(Exprs.IterationVarRef); 1961 Dir->setLastIteration(Exprs.LastIteration); 1962 Dir->setCalcLastIteration(Exprs.CalcLastIteration); 1963 Dir->setPreCond(Exprs.PreCond); 1964 Dir->setCond(Exprs.Cond); 1965 Dir->setInit(Exprs.Init); 1966 Dir->setInc(Exprs.Inc); 1967 Dir->setIsLastIterVariable(Exprs.IL); 1968 Dir->setLowerBoundVariable(Exprs.LB); 1969 Dir->setUpperBoundVariable(Exprs.UB); 1970 Dir->setStrideVariable(Exprs.ST); 1971 Dir->setEnsureUpperBound(Exprs.EUB); 1972 Dir->setNextLowerBound(Exprs.NLB); 1973 Dir->setNextUpperBound(Exprs.NUB); 1974 Dir->setCounters(Exprs.Counters); 1975 Dir->setPrivateCounters(Exprs.PrivateCounters); 1976 Dir->setInits(Exprs.Inits); 1977 Dir->setUpdates(Exprs.Updates); 1978 Dir->setFinals(Exprs.Finals); 1979 return Dir; 1980 } 1981 1982 OMPParallelForSimdDirective * 1983 OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C, 1984 unsigned NumClauses, 1985 unsigned CollapsedNum, EmptyShell) { 1986 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), 1987 llvm::alignOf<OMPClause *>()); 1988 void *Mem = C.Allocate( 1989 Size + sizeof(OMPClause *) * NumClauses + 1990 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); 1991 return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); 1992 } 1993 1994 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( 1995 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1996 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) { 1997 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), 1998 llvm::alignOf<OMPClause *>()); 1999 void *Mem = 2000 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 2001 OMPParallelSectionsDirective *Dir = 2002 new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); 2003 Dir->setClauses(Clauses); 2004 Dir->setAssociatedStmt(AssociatedStmt); 2005 Dir->setHasCancel(HasCancel); 2006 return Dir; 2007 } 2008 2009 OMPParallelSectionsDirective * 2010 OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, 2011 unsigned NumClauses, EmptyShell) { 2012 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), 2013 llvm::alignOf<OMPClause *>()); 2014 void *Mem = 2015 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 2016 return new (Mem) OMPParallelSectionsDirective(NumClauses); 2017 } 2018 2019 OMPTaskDirective * 2020 OMPTaskDirective::Create(const ASTContext &C, SourceLocation StartLoc, 2021 SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, 2022 Stmt *AssociatedStmt, bool HasCancel) { 2023 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), 2024 llvm::alignOf<OMPClause *>()); 2025 void *Mem = 2026 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 2027 OMPTaskDirective *Dir = 2028 new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); 2029 Dir->setClauses(Clauses); 2030 Dir->setAssociatedStmt(AssociatedStmt); 2031 Dir->setHasCancel(HasCancel); 2032 return Dir; 2033 } 2034 2035 OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, 2036 unsigned NumClauses, 2037 EmptyShell) { 2038 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), 2039 llvm::alignOf<OMPClause *>()); 2040 void *Mem = 2041 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 2042 return new (Mem) OMPTaskDirective(NumClauses); 2043 } 2044 2045 OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, 2046 SourceLocation StartLoc, 2047 SourceLocation EndLoc) { 2048 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); 2049 OMPTaskyieldDirective *Dir = 2050 new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); 2051 return Dir; 2052 } 2053 2054 OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, 2055 EmptyShell) { 2056 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); 2057 return new (Mem) OMPTaskyieldDirective(); 2058 } 2059 2060 OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, 2061 SourceLocation StartLoc, 2062 SourceLocation EndLoc) { 2063 void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); 2064 OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); 2065 return Dir; 2066 } 2067 2068 OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, 2069 EmptyShell) { 2070 void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); 2071 return new (Mem) OMPBarrierDirective(); 2072 } 2073 2074 OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, 2075 SourceLocation StartLoc, 2076 SourceLocation EndLoc) { 2077 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); 2078 OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); 2079 return Dir; 2080 } 2081 2082 OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, 2083 EmptyShell) { 2084 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); 2085 return new (Mem) OMPTaskwaitDirective(); 2086 } 2087 2088 OMPTaskgroupDirective *OMPTaskgroupDirective::Create(const ASTContext &C, 2089 SourceLocation StartLoc, 2090 SourceLocation EndLoc, 2091 Stmt *AssociatedStmt) { 2092 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective), 2093 llvm::alignOf<Stmt *>()); 2094 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 2095 OMPTaskgroupDirective *Dir = 2096 new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc); 2097 Dir->setAssociatedStmt(AssociatedStmt); 2098 return Dir; 2099 } 2100 2101 OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C, 2102 EmptyShell) { 2103 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective), 2104 llvm::alignOf<Stmt *>()); 2105 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 2106 return new (Mem) OMPTaskgroupDirective(); 2107 } 2108 2109 OMPCancellationPointDirective *OMPCancellationPointDirective::Create( 2110 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 2111 OpenMPDirectiveKind CancelRegion) { 2112 unsigned Size = llvm::RoundUpToAlignment( 2113 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>()); 2114 void *Mem = C.Allocate(Size); 2115 OMPCancellationPointDirective *Dir = 2116 new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc); 2117 Dir->setCancelRegion(CancelRegion); 2118 return Dir; 2119 } 2120 2121 OMPCancellationPointDirective * 2122 OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) { 2123 unsigned Size = llvm::RoundUpToAlignment( 2124 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>()); 2125 void *Mem = C.Allocate(Size); 2126 return new (Mem) OMPCancellationPointDirective(); 2127 } 2128 2129 OMPCancelDirective * 2130 OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc, 2131 SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, 2132 OpenMPDirectiveKind CancelRegion) { 2133 unsigned Size = llvm::RoundUpToAlignment( 2134 sizeof(OMPCancelDirective) + sizeof(OMPClause *) * Clauses.size(), 2135 llvm::alignOf<Stmt *>()); 2136 void *Mem = C.Allocate(Size); 2137 OMPCancelDirective *Dir = 2138 new (Mem) OMPCancelDirective(StartLoc, EndLoc, Clauses.size()); 2139 Dir->setClauses(Clauses); 2140 Dir->setCancelRegion(CancelRegion); 2141 return Dir; 2142 } 2143 2144 OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C, 2145 unsigned NumClauses, 2146 EmptyShell) { 2147 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective) + 2148 sizeof(OMPClause *) * NumClauses, 2149 llvm::alignOf<Stmt *>()); 2150 void *Mem = C.Allocate(Size); 2151 return new (Mem) OMPCancelDirective(NumClauses); 2152 } 2153 2154 OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, 2155 SourceLocation StartLoc, 2156 SourceLocation EndLoc, 2157 ArrayRef<OMPClause *> Clauses) { 2158 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), 2159 llvm::alignOf<OMPClause *>()); 2160 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); 2161 OMPFlushDirective *Dir = 2162 new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); 2163 Dir->setClauses(Clauses); 2164 return Dir; 2165 } 2166 2167 OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, 2168 unsigned NumClauses, 2169 EmptyShell) { 2170 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), 2171 llvm::alignOf<OMPClause *>()); 2172 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); 2173 return new (Mem) OMPFlushDirective(NumClauses); 2174 } 2175 2176 OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C, 2177 SourceLocation StartLoc, 2178 SourceLocation EndLoc, 2179 Stmt *AssociatedStmt) { 2180 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), 2181 llvm::alignOf<Stmt *>()); 2182 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 2183 OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc); 2184 Dir->setAssociatedStmt(AssociatedStmt); 2185 return Dir; 2186 } 2187 2188 OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C, 2189 EmptyShell) { 2190 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), 2191 llvm::alignOf<Stmt *>()); 2192 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 2193 return new (Mem) OMPOrderedDirective(); 2194 } 2195 2196 OMPAtomicDirective *OMPAtomicDirective::Create( 2197 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 2198 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V, 2199 Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) { 2200 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), 2201 llvm::alignOf<OMPClause *>()); 2202 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 2203 5 * sizeof(Stmt *)); 2204 OMPAtomicDirective *Dir = 2205 new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); 2206 Dir->setClauses(Clauses); 2207 Dir->setAssociatedStmt(AssociatedStmt); 2208 Dir->setX(X); 2209 Dir->setV(V); 2210 Dir->setExpr(E); 2211 Dir->setUpdateExpr(UE); 2212 Dir->IsXLHSInRHSPart = IsXLHSInRHSPart; 2213 Dir->IsPostfixUpdate = IsPostfixUpdate; 2214 return Dir; 2215 } 2216 2217 OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C, 2218 unsigned NumClauses, 2219 EmptyShell) { 2220 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), 2221 llvm::alignOf<OMPClause *>()); 2222 void *Mem = 2223 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *)); 2224 return new (Mem) OMPAtomicDirective(NumClauses); 2225 } 2226 2227 OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C, 2228 SourceLocation StartLoc, 2229 SourceLocation EndLoc, 2230 ArrayRef<OMPClause *> Clauses, 2231 Stmt *AssociatedStmt) { 2232 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), 2233 llvm::alignOf<OMPClause *>()); 2234 void *Mem = 2235 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 2236 OMPTargetDirective *Dir = 2237 new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); 2238 Dir->setClauses(Clauses); 2239 Dir->setAssociatedStmt(AssociatedStmt); 2240 return Dir; 2241 } 2242 2243 OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, 2244 unsigned NumClauses, 2245 EmptyShell) { 2246 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), 2247 llvm::alignOf<OMPClause *>()); 2248 void *Mem = 2249 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 2250 return new (Mem) OMPTargetDirective(NumClauses); 2251 } 2252 2253 OMPTargetDataDirective *OMPTargetDataDirective::Create( 2254 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 2255 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { 2256 void *Mem = 2257 C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective), 2258 llvm::alignOf<OMPClause *>()) + 2259 sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 2260 OMPTargetDataDirective *Dir = 2261 new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size()); 2262 Dir->setClauses(Clauses); 2263 Dir->setAssociatedStmt(AssociatedStmt); 2264 return Dir; 2265 } 2266 2267 OMPTargetDataDirective *OMPTargetDataDirective::CreateEmpty(const ASTContext &C, 2268 unsigned N, 2269 EmptyShell) { 2270 void *Mem = 2271 C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective), 2272 llvm::alignOf<OMPClause *>()) + 2273 sizeof(OMPClause *) * N + sizeof(Stmt *)); 2274 return new (Mem) OMPTargetDataDirective(N); 2275 } 2276 2277 OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, 2278 SourceLocation StartLoc, 2279 SourceLocation EndLoc, 2280 ArrayRef<OMPClause *> Clauses, 2281 Stmt *AssociatedStmt) { 2282 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), 2283 llvm::alignOf<OMPClause *>()); 2284 void *Mem = 2285 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 2286 OMPTeamsDirective *Dir = 2287 new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); 2288 Dir->setClauses(Clauses); 2289 Dir->setAssociatedStmt(AssociatedStmt); 2290 return Dir; 2291 } 2292 2293 OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, 2294 unsigned NumClauses, 2295 EmptyShell) { 2296 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), 2297 llvm::alignOf<OMPClause *>()); 2298 void *Mem = 2299 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 2300 return new (Mem) OMPTeamsDirective(NumClauses); 2301 } 2302