1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the Stmt::Profile method, which builds a unique bit 10 // representation that identifies a statement/expression. 11 // 12 //===----------------------------------------------------------------------===// 13 #include "clang/AST/ASTContext.h" 14 #include "clang/AST/DeclCXX.h" 15 #include "clang/AST/DeclObjC.h" 16 #include "clang/AST/DeclTemplate.h" 17 #include "clang/AST/Expr.h" 18 #include "clang/AST/ExprCXX.h" 19 #include "clang/AST/ExprObjC.h" 20 #include "clang/AST/ExprOpenMP.h" 21 #include "clang/AST/ODRHash.h" 22 #include "clang/AST/OpenMPClause.h" 23 #include "clang/AST/StmtVisitor.h" 24 #include "llvm/ADT/FoldingSet.h" 25 using namespace clang; 26 27 namespace { 28 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> { 29 protected: 30 llvm::FoldingSetNodeID &ID; 31 bool Canonical; 32 bool ProfileLambdaExpr; 33 34 public: 35 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical, 36 bool ProfileLambdaExpr) 37 : ID(ID), Canonical(Canonical), ProfileLambdaExpr(ProfileLambdaExpr) {} 38 39 virtual ~StmtProfiler() {} 40 41 void VisitStmt(const Stmt *S); 42 43 void VisitStmtNoChildren(const Stmt *S) { 44 HandleStmtClass(S->getStmtClass()); 45 } 46 47 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0; 48 49 #define STMT(Node, Base) void Visit##Node(const Node *S); 50 #include "clang/AST/StmtNodes.inc" 51 52 /// Visit a declaration that is referenced within an expression 53 /// or statement. 54 virtual void VisitDecl(const Decl *D) = 0; 55 56 /// Visit a type that is referenced within an expression or 57 /// statement. 58 virtual void VisitType(QualType T) = 0; 59 60 /// Visit a name that occurs within an expression or statement. 61 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0; 62 63 /// Visit identifiers that are not in Decl's or Type's. 64 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0; 65 66 /// Visit a nested-name-specifier that occurs within an expression 67 /// or statement. 68 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0; 69 70 /// Visit a template name that occurs within an expression or 71 /// statement. 72 virtual void VisitTemplateName(TemplateName Name) = 0; 73 74 /// Visit template arguments that occur within an expression or 75 /// statement. 76 void VisitTemplateArguments(const TemplateArgumentLoc *Args, 77 unsigned NumArgs); 78 79 /// Visit a single template argument. 80 void VisitTemplateArgument(const TemplateArgument &Arg); 81 }; 82 83 class StmtProfilerWithPointers : public StmtProfiler { 84 const ASTContext &Context; 85 86 public: 87 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID, 88 const ASTContext &Context, bool Canonical, 89 bool ProfileLambdaExpr) 90 : StmtProfiler(ID, Canonical, ProfileLambdaExpr), Context(Context) {} 91 92 private: 93 void HandleStmtClass(Stmt::StmtClass SC) override { 94 ID.AddInteger(SC); 95 } 96 97 void VisitDecl(const Decl *D) override { 98 ID.AddInteger(D ? D->getKind() : 0); 99 100 if (Canonical && D) { 101 if (const NonTypeTemplateParmDecl *NTTP = 102 dyn_cast<NonTypeTemplateParmDecl>(D)) { 103 ID.AddInteger(NTTP->getDepth()); 104 ID.AddInteger(NTTP->getIndex()); 105 ID.AddBoolean(NTTP->isParameterPack()); 106 // C++20 [temp.over.link]p6: 107 // Two template-parameters are equivalent under the following 108 // conditions: [...] if they declare non-type template parameters, 109 // they have equivalent types ignoring the use of type-constraints 110 // for placeholder types 111 // 112 // TODO: Why do we need to include the type in the profile? It's not 113 // part of the mangling. 114 VisitType(Context.getUnconstrainedType(NTTP->getType())); 115 return; 116 } 117 118 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { 119 // The Itanium C++ ABI uses the type, scope depth, and scope 120 // index of a parameter when mangling expressions that involve 121 // function parameters, so we will use the parameter's type for 122 // establishing function parameter identity. That way, our 123 // definition of "equivalent" (per C++ [temp.over.link]) is at 124 // least as strong as the definition of "equivalent" used for 125 // name mangling. 126 // 127 // TODO: The Itanium C++ ABI only uses the top-level cv-qualifiers, 128 // not the entirety of the type. 129 VisitType(Parm->getType()); 130 ID.AddInteger(Parm->getFunctionScopeDepth()); 131 ID.AddInteger(Parm->getFunctionScopeIndex()); 132 return; 133 } 134 135 if (const TemplateTypeParmDecl *TTP = 136 dyn_cast<TemplateTypeParmDecl>(D)) { 137 ID.AddInteger(TTP->getDepth()); 138 ID.AddInteger(TTP->getIndex()); 139 ID.AddBoolean(TTP->isParameterPack()); 140 return; 141 } 142 143 if (const TemplateTemplateParmDecl *TTP = 144 dyn_cast<TemplateTemplateParmDecl>(D)) { 145 ID.AddInteger(TTP->getDepth()); 146 ID.AddInteger(TTP->getIndex()); 147 ID.AddBoolean(TTP->isParameterPack()); 148 return; 149 } 150 } 151 152 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr); 153 } 154 155 void VisitType(QualType T) override { 156 if (Canonical && !T.isNull()) 157 T = Context.getCanonicalType(T); 158 159 ID.AddPointer(T.getAsOpaquePtr()); 160 } 161 162 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override { 163 ID.AddPointer(Name.getAsOpaquePtr()); 164 } 165 166 void VisitIdentifierInfo(IdentifierInfo *II) override { 167 ID.AddPointer(II); 168 } 169 170 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override { 171 if (Canonical) 172 NNS = Context.getCanonicalNestedNameSpecifier(NNS); 173 ID.AddPointer(NNS); 174 } 175 176 void VisitTemplateName(TemplateName Name) override { 177 if (Canonical) 178 Name = Context.getCanonicalTemplateName(Name); 179 180 Name.Profile(ID); 181 } 182 }; 183 184 class StmtProfilerWithoutPointers : public StmtProfiler { 185 ODRHash &Hash; 186 public: 187 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash) 188 : StmtProfiler(ID, /*Canonical=*/false, /*ProfileLambdaExpr=*/false), 189 Hash(Hash) {} 190 191 private: 192 void HandleStmtClass(Stmt::StmtClass SC) override { 193 if (SC == Stmt::UnresolvedLookupExprClass) { 194 // Pretend that the name looked up is a Decl due to how templates 195 // handle some Decl lookups. 196 ID.AddInteger(Stmt::DeclRefExprClass); 197 } else { 198 ID.AddInteger(SC); 199 } 200 } 201 202 void VisitType(QualType T) override { 203 Hash.AddQualType(T); 204 } 205 206 void VisitName(DeclarationName Name, bool TreatAsDecl) override { 207 if (TreatAsDecl) { 208 // A Decl can be null, so each Decl is preceded by a boolean to 209 // store its nullness. Add a boolean here to match. 210 ID.AddBoolean(true); 211 } 212 Hash.AddDeclarationName(Name, TreatAsDecl); 213 } 214 void VisitIdentifierInfo(IdentifierInfo *II) override { 215 ID.AddBoolean(II); 216 if (II) { 217 Hash.AddIdentifierInfo(II); 218 } 219 } 220 void VisitDecl(const Decl *D) override { 221 ID.AddBoolean(D); 222 if (D) { 223 Hash.AddDecl(D); 224 } 225 } 226 void VisitTemplateName(TemplateName Name) override { 227 Hash.AddTemplateName(Name); 228 } 229 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override { 230 ID.AddBoolean(NNS); 231 if (NNS) { 232 Hash.AddNestedNameSpecifier(NNS); 233 } 234 } 235 }; 236 } 237 238 void StmtProfiler::VisitStmt(const Stmt *S) { 239 assert(S && "Requires non-null Stmt pointer"); 240 241 VisitStmtNoChildren(S); 242 243 for (const Stmt *SubStmt : S->children()) { 244 if (SubStmt) 245 Visit(SubStmt); 246 else 247 ID.AddInteger(0); 248 } 249 } 250 251 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) { 252 VisitStmt(S); 253 for (const auto *D : S->decls()) 254 VisitDecl(D); 255 } 256 257 void StmtProfiler::VisitNullStmt(const NullStmt *S) { 258 VisitStmt(S); 259 } 260 261 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) { 262 VisitStmt(S); 263 } 264 265 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) { 266 VisitStmt(S); 267 } 268 269 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) { 270 VisitStmt(S); 271 } 272 273 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) { 274 VisitStmt(S); 275 VisitDecl(S->getDecl()); 276 } 277 278 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) { 279 VisitStmt(S); 280 // TODO: maybe visit attributes? 281 } 282 283 void StmtProfiler::VisitIfStmt(const IfStmt *S) { 284 VisitStmt(S); 285 VisitDecl(S->getConditionVariable()); 286 } 287 288 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) { 289 VisitStmt(S); 290 VisitDecl(S->getConditionVariable()); 291 } 292 293 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) { 294 VisitStmt(S); 295 VisitDecl(S->getConditionVariable()); 296 } 297 298 void StmtProfiler::VisitDoStmt(const DoStmt *S) { 299 VisitStmt(S); 300 } 301 302 void StmtProfiler::VisitForStmt(const ForStmt *S) { 303 VisitStmt(S); 304 } 305 306 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) { 307 VisitStmt(S); 308 VisitDecl(S->getLabel()); 309 } 310 311 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) { 312 VisitStmt(S); 313 } 314 315 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) { 316 VisitStmt(S); 317 } 318 319 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) { 320 VisitStmt(S); 321 } 322 323 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) { 324 VisitStmt(S); 325 } 326 327 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) { 328 VisitStmt(S); 329 ID.AddBoolean(S->isVolatile()); 330 ID.AddBoolean(S->isSimple()); 331 VisitStringLiteral(S->getAsmString()); 332 ID.AddInteger(S->getNumOutputs()); 333 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { 334 ID.AddString(S->getOutputName(I)); 335 VisitStringLiteral(S->getOutputConstraintLiteral(I)); 336 } 337 ID.AddInteger(S->getNumInputs()); 338 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { 339 ID.AddString(S->getInputName(I)); 340 VisitStringLiteral(S->getInputConstraintLiteral(I)); 341 } 342 ID.AddInteger(S->getNumClobbers()); 343 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) 344 VisitStringLiteral(S->getClobberStringLiteral(I)); 345 ID.AddInteger(S->getNumLabels()); 346 for (auto *L : S->labels()) 347 VisitDecl(L->getLabel()); 348 } 349 350 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) { 351 // FIXME: Implement MS style inline asm statement profiler. 352 VisitStmt(S); 353 } 354 355 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) { 356 VisitStmt(S); 357 VisitType(S->getCaughtType()); 358 } 359 360 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) { 361 VisitStmt(S); 362 } 363 364 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) { 365 VisitStmt(S); 366 } 367 368 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) { 369 VisitStmt(S); 370 ID.AddBoolean(S->isIfExists()); 371 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier()); 372 VisitName(S->getNameInfo().getName()); 373 } 374 375 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) { 376 VisitStmt(S); 377 } 378 379 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) { 380 VisitStmt(S); 381 } 382 383 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) { 384 VisitStmt(S); 385 } 386 387 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) { 388 VisitStmt(S); 389 } 390 391 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) { 392 VisitStmt(S); 393 } 394 395 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { 396 VisitStmt(S); 397 } 398 399 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) { 400 VisitStmt(S); 401 ID.AddBoolean(S->hasEllipsis()); 402 if (S->getCatchParamDecl()) 403 VisitType(S->getCatchParamDecl()->getType()); 404 } 405 406 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) { 407 VisitStmt(S); 408 } 409 410 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) { 411 VisitStmt(S); 412 } 413 414 void 415 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) { 416 VisitStmt(S); 417 } 418 419 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) { 420 VisitStmt(S); 421 } 422 423 void 424 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) { 425 VisitStmt(S); 426 } 427 428 namespace { 429 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> { 430 StmtProfiler *Profiler; 431 /// Process clauses with list of variables. 432 template <typename T> 433 void VisitOMPClauseList(T *Node); 434 435 public: 436 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { } 437 #define GEN_CLANG_CLAUSE_CLASS 438 #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C); 439 #include "llvm/Frontend/OpenMP/OMP.inc" 440 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C); 441 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C); 442 }; 443 444 void OMPClauseProfiler::VistOMPClauseWithPreInit( 445 const OMPClauseWithPreInit *C) { 446 if (auto *S = C->getPreInitStmt()) 447 Profiler->VisitStmt(S); 448 } 449 450 void OMPClauseProfiler::VistOMPClauseWithPostUpdate( 451 const OMPClauseWithPostUpdate *C) { 452 VistOMPClauseWithPreInit(C); 453 if (auto *E = C->getPostUpdateExpr()) 454 Profiler->VisitStmt(E); 455 } 456 457 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) { 458 VistOMPClauseWithPreInit(C); 459 if (C->getCondition()) 460 Profiler->VisitStmt(C->getCondition()); 461 } 462 463 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) { 464 VistOMPClauseWithPreInit(C); 465 if (C->getCondition()) 466 Profiler->VisitStmt(C->getCondition()); 467 } 468 469 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) { 470 VistOMPClauseWithPreInit(C); 471 if (C->getNumThreads()) 472 Profiler->VisitStmt(C->getNumThreads()); 473 } 474 475 void OMPClauseProfiler::VisitOMPAlignClause(const OMPAlignClause *C) { 476 if (C->getAlignment()) 477 Profiler->VisitStmt(C->getAlignment()); 478 } 479 480 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) { 481 if (C->getSafelen()) 482 Profiler->VisitStmt(C->getSafelen()); 483 } 484 485 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) { 486 if (C->getSimdlen()) 487 Profiler->VisitStmt(C->getSimdlen()); 488 } 489 490 void OMPClauseProfiler::VisitOMPSizesClause(const OMPSizesClause *C) { 491 for (auto *E : C->getSizesRefs()) 492 if (E) 493 Profiler->VisitExpr(E); 494 } 495 496 void OMPClauseProfiler::VisitOMPFullClause(const OMPFullClause *C) {} 497 498 void OMPClauseProfiler::VisitOMPPartialClause(const OMPPartialClause *C) { 499 if (const Expr *Factor = C->getFactor()) 500 Profiler->VisitExpr(Factor); 501 } 502 503 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) { 504 if (C->getAllocator()) 505 Profiler->VisitStmt(C->getAllocator()); 506 } 507 508 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) { 509 if (C->getNumForLoops()) 510 Profiler->VisitStmt(C->getNumForLoops()); 511 } 512 513 void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) { 514 if (Expr *Evt = C->getEventHandler()) 515 Profiler->VisitStmt(Evt); 516 } 517 518 void OMPClauseProfiler::VisitOMPNovariantsClause(const OMPNovariantsClause *C) { 519 VistOMPClauseWithPreInit(C); 520 if (C->getCondition()) 521 Profiler->VisitStmt(C->getCondition()); 522 } 523 524 void OMPClauseProfiler::VisitOMPNocontextClause(const OMPNocontextClause *C) { 525 VistOMPClauseWithPreInit(C); 526 if (C->getCondition()) 527 Profiler->VisitStmt(C->getCondition()); 528 } 529 530 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { } 531 532 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { } 533 534 void OMPClauseProfiler::VisitOMPUnifiedAddressClause( 535 const OMPUnifiedAddressClause *C) {} 536 537 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause( 538 const OMPUnifiedSharedMemoryClause *C) {} 539 540 void OMPClauseProfiler::VisitOMPReverseOffloadClause( 541 const OMPReverseOffloadClause *C) {} 542 543 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause( 544 const OMPDynamicAllocatorsClause *C) {} 545 546 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause( 547 const OMPAtomicDefaultMemOrderClause *C) {} 548 549 void OMPClauseProfiler::VisitOMPAtClause(const OMPAtClause *C) {} 550 551 void OMPClauseProfiler::VisitOMPSeverityClause(const OMPSeverityClause *C) {} 552 553 void OMPClauseProfiler::VisitOMPMessageClause(const OMPMessageClause *C) { 554 if (C->getMessageString()) 555 Profiler->VisitStmt(C->getMessageString()); 556 } 557 558 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { 559 VistOMPClauseWithPreInit(C); 560 if (auto *S = C->getChunkSize()) 561 Profiler->VisitStmt(S); 562 } 563 564 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) { 565 if (auto *Num = C->getNumForLoops()) 566 Profiler->VisitStmt(Num); 567 } 568 569 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {} 570 571 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {} 572 573 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {} 574 575 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {} 576 577 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {} 578 579 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {} 580 581 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {} 582 583 void OMPClauseProfiler::VisitOMPCompareClause(const OMPCompareClause *) {} 584 585 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} 586 587 void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {} 588 589 void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {} 590 591 void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {} 592 593 void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {} 594 595 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {} 596 597 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {} 598 599 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {} 600 601 void OMPClauseProfiler::VisitOMPInitClause(const OMPInitClause *C) { 602 VisitOMPClauseList(C); 603 } 604 605 void OMPClauseProfiler::VisitOMPUseClause(const OMPUseClause *C) { 606 if (C->getInteropVar()) 607 Profiler->VisitStmt(C->getInteropVar()); 608 } 609 610 void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *C) { 611 if (C->getInteropVar()) 612 Profiler->VisitStmt(C->getInteropVar()); 613 } 614 615 void OMPClauseProfiler::VisitOMPFilterClause(const OMPFilterClause *C) { 616 VistOMPClauseWithPreInit(C); 617 if (C->getThreadID()) 618 Profiler->VisitStmt(C->getThreadID()); 619 } 620 621 template<typename T> 622 void OMPClauseProfiler::VisitOMPClauseList(T *Node) { 623 for (auto *E : Node->varlists()) { 624 if (E) 625 Profiler->VisitStmt(E); 626 } 627 } 628 629 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) { 630 VisitOMPClauseList(C); 631 for (auto *E : C->private_copies()) { 632 if (E) 633 Profiler->VisitStmt(E); 634 } 635 } 636 void 637 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) { 638 VisitOMPClauseList(C); 639 VistOMPClauseWithPreInit(C); 640 for (auto *E : C->private_copies()) { 641 if (E) 642 Profiler->VisitStmt(E); 643 } 644 for (auto *E : C->inits()) { 645 if (E) 646 Profiler->VisitStmt(E); 647 } 648 } 649 void 650 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) { 651 VisitOMPClauseList(C); 652 VistOMPClauseWithPostUpdate(C); 653 for (auto *E : C->source_exprs()) { 654 if (E) 655 Profiler->VisitStmt(E); 656 } 657 for (auto *E : C->destination_exprs()) { 658 if (E) 659 Profiler->VisitStmt(E); 660 } 661 for (auto *E : C->assignment_ops()) { 662 if (E) 663 Profiler->VisitStmt(E); 664 } 665 } 666 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) { 667 VisitOMPClauseList(C); 668 } 669 void OMPClauseProfiler::VisitOMPReductionClause( 670 const OMPReductionClause *C) { 671 Profiler->VisitNestedNameSpecifier( 672 C->getQualifierLoc().getNestedNameSpecifier()); 673 Profiler->VisitName(C->getNameInfo().getName()); 674 VisitOMPClauseList(C); 675 VistOMPClauseWithPostUpdate(C); 676 for (auto *E : C->privates()) { 677 if (E) 678 Profiler->VisitStmt(E); 679 } 680 for (auto *E : C->lhs_exprs()) { 681 if (E) 682 Profiler->VisitStmt(E); 683 } 684 for (auto *E : C->rhs_exprs()) { 685 if (E) 686 Profiler->VisitStmt(E); 687 } 688 for (auto *E : C->reduction_ops()) { 689 if (E) 690 Profiler->VisitStmt(E); 691 } 692 if (C->getModifier() == clang::OMPC_REDUCTION_inscan) { 693 for (auto *E : C->copy_ops()) { 694 if (E) 695 Profiler->VisitStmt(E); 696 } 697 for (auto *E : C->copy_array_temps()) { 698 if (E) 699 Profiler->VisitStmt(E); 700 } 701 for (auto *E : C->copy_array_elems()) { 702 if (E) 703 Profiler->VisitStmt(E); 704 } 705 } 706 } 707 void OMPClauseProfiler::VisitOMPTaskReductionClause( 708 const OMPTaskReductionClause *C) { 709 Profiler->VisitNestedNameSpecifier( 710 C->getQualifierLoc().getNestedNameSpecifier()); 711 Profiler->VisitName(C->getNameInfo().getName()); 712 VisitOMPClauseList(C); 713 VistOMPClauseWithPostUpdate(C); 714 for (auto *E : C->privates()) { 715 if (E) 716 Profiler->VisitStmt(E); 717 } 718 for (auto *E : C->lhs_exprs()) { 719 if (E) 720 Profiler->VisitStmt(E); 721 } 722 for (auto *E : C->rhs_exprs()) { 723 if (E) 724 Profiler->VisitStmt(E); 725 } 726 for (auto *E : C->reduction_ops()) { 727 if (E) 728 Profiler->VisitStmt(E); 729 } 730 } 731 void OMPClauseProfiler::VisitOMPInReductionClause( 732 const OMPInReductionClause *C) { 733 Profiler->VisitNestedNameSpecifier( 734 C->getQualifierLoc().getNestedNameSpecifier()); 735 Profiler->VisitName(C->getNameInfo().getName()); 736 VisitOMPClauseList(C); 737 VistOMPClauseWithPostUpdate(C); 738 for (auto *E : C->privates()) { 739 if (E) 740 Profiler->VisitStmt(E); 741 } 742 for (auto *E : C->lhs_exprs()) { 743 if (E) 744 Profiler->VisitStmt(E); 745 } 746 for (auto *E : C->rhs_exprs()) { 747 if (E) 748 Profiler->VisitStmt(E); 749 } 750 for (auto *E : C->reduction_ops()) { 751 if (E) 752 Profiler->VisitStmt(E); 753 } 754 for (auto *E : C->taskgroup_descriptors()) { 755 if (E) 756 Profiler->VisitStmt(E); 757 } 758 } 759 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) { 760 VisitOMPClauseList(C); 761 VistOMPClauseWithPostUpdate(C); 762 for (auto *E : C->privates()) { 763 if (E) 764 Profiler->VisitStmt(E); 765 } 766 for (auto *E : C->inits()) { 767 if (E) 768 Profiler->VisitStmt(E); 769 } 770 for (auto *E : C->updates()) { 771 if (E) 772 Profiler->VisitStmt(E); 773 } 774 for (auto *E : C->finals()) { 775 if (E) 776 Profiler->VisitStmt(E); 777 } 778 if (C->getStep()) 779 Profiler->VisitStmt(C->getStep()); 780 if (C->getCalcStep()) 781 Profiler->VisitStmt(C->getCalcStep()); 782 } 783 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) { 784 VisitOMPClauseList(C); 785 if (C->getAlignment()) 786 Profiler->VisitStmt(C->getAlignment()); 787 } 788 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) { 789 VisitOMPClauseList(C); 790 for (auto *E : C->source_exprs()) { 791 if (E) 792 Profiler->VisitStmt(E); 793 } 794 for (auto *E : C->destination_exprs()) { 795 if (E) 796 Profiler->VisitStmt(E); 797 } 798 for (auto *E : C->assignment_ops()) { 799 if (E) 800 Profiler->VisitStmt(E); 801 } 802 } 803 void 804 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) { 805 VisitOMPClauseList(C); 806 for (auto *E : C->source_exprs()) { 807 if (E) 808 Profiler->VisitStmt(E); 809 } 810 for (auto *E : C->destination_exprs()) { 811 if (E) 812 Profiler->VisitStmt(E); 813 } 814 for (auto *E : C->assignment_ops()) { 815 if (E) 816 Profiler->VisitStmt(E); 817 } 818 } 819 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) { 820 VisitOMPClauseList(C); 821 } 822 void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) { 823 if (const Expr *Depobj = C->getDepobj()) 824 Profiler->VisitStmt(Depobj); 825 } 826 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) { 827 VisitOMPClauseList(C); 828 } 829 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) { 830 if (C->getDevice()) 831 Profiler->VisitStmt(C->getDevice()); 832 } 833 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) { 834 VisitOMPClauseList(C); 835 } 836 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) { 837 if (Expr *Allocator = C->getAllocator()) 838 Profiler->VisitStmt(Allocator); 839 VisitOMPClauseList(C); 840 } 841 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { 842 VistOMPClauseWithPreInit(C); 843 if (C->getNumTeams()) 844 Profiler->VisitStmt(C->getNumTeams()); 845 } 846 void OMPClauseProfiler::VisitOMPThreadLimitClause( 847 const OMPThreadLimitClause *C) { 848 VistOMPClauseWithPreInit(C); 849 if (C->getThreadLimit()) 850 Profiler->VisitStmt(C->getThreadLimit()); 851 } 852 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) { 853 VistOMPClauseWithPreInit(C); 854 if (C->getPriority()) 855 Profiler->VisitStmt(C->getPriority()); 856 } 857 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) { 858 VistOMPClauseWithPreInit(C); 859 if (C->getGrainsize()) 860 Profiler->VisitStmt(C->getGrainsize()); 861 } 862 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) { 863 VistOMPClauseWithPreInit(C); 864 if (C->getNumTasks()) 865 Profiler->VisitStmt(C->getNumTasks()); 866 } 867 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) { 868 if (C->getHint()) 869 Profiler->VisitStmt(C->getHint()); 870 } 871 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) { 872 VisitOMPClauseList(C); 873 } 874 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) { 875 VisitOMPClauseList(C); 876 } 877 void OMPClauseProfiler::VisitOMPUseDevicePtrClause( 878 const OMPUseDevicePtrClause *C) { 879 VisitOMPClauseList(C); 880 } 881 void OMPClauseProfiler::VisitOMPUseDeviceAddrClause( 882 const OMPUseDeviceAddrClause *C) { 883 VisitOMPClauseList(C); 884 } 885 void OMPClauseProfiler::VisitOMPIsDevicePtrClause( 886 const OMPIsDevicePtrClause *C) { 887 VisitOMPClauseList(C); 888 } 889 void OMPClauseProfiler::VisitOMPHasDeviceAddrClause( 890 const OMPHasDeviceAddrClause *C) { 891 VisitOMPClauseList(C); 892 } 893 void OMPClauseProfiler::VisitOMPNontemporalClause( 894 const OMPNontemporalClause *C) { 895 VisitOMPClauseList(C); 896 for (auto *E : C->private_refs()) 897 Profiler->VisitStmt(E); 898 } 899 void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) { 900 VisitOMPClauseList(C); 901 } 902 void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) { 903 VisitOMPClauseList(C); 904 } 905 void OMPClauseProfiler::VisitOMPUsesAllocatorsClause( 906 const OMPUsesAllocatorsClause *C) { 907 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { 908 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I); 909 Profiler->VisitStmt(D.Allocator); 910 if (D.AllocatorTraits) 911 Profiler->VisitStmt(D.AllocatorTraits); 912 } 913 } 914 void OMPClauseProfiler::VisitOMPAffinityClause(const OMPAffinityClause *C) { 915 if (const Expr *Modifier = C->getModifier()) 916 Profiler->VisitStmt(Modifier); 917 for (const Expr *E : C->varlists()) 918 Profiler->VisitStmt(E); 919 } 920 void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {} 921 void OMPClauseProfiler::VisitOMPBindClause(const OMPBindClause *C) {} 922 void OMPClauseProfiler::VisitOMPXDynCGroupMemClause( 923 const OMPXDynCGroupMemClause *C) { 924 VistOMPClauseWithPreInit(C); 925 if (Expr *Size = C->getSize()) 926 Profiler->VisitStmt(Size); 927 } 928 void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) { 929 VisitOMPClauseList(C); 930 } 931 } // namespace 932 933 void 934 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { 935 VisitStmt(S); 936 OMPClauseProfiler P(this); 937 ArrayRef<OMPClause *> Clauses = S->clauses(); 938 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 939 I != E; ++I) 940 if (*I) 941 P.Visit(*I); 942 } 943 944 void StmtProfiler::VisitOMPCanonicalLoop(const OMPCanonicalLoop *L) { 945 VisitStmt(L); 946 } 947 948 void StmtProfiler::VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *S) { 949 VisitOMPExecutableDirective(S); 950 } 951 952 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { 953 VisitOMPLoopBasedDirective(S); 954 } 955 956 void StmtProfiler::VisitOMPMetaDirective(const OMPMetaDirective *S) { 957 VisitOMPExecutableDirective(S); 958 } 959 960 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { 961 VisitOMPExecutableDirective(S); 962 } 963 964 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { 965 VisitOMPLoopDirective(S); 966 } 967 968 void StmtProfiler::VisitOMPLoopTransformationDirective( 969 const OMPLoopTransformationDirective *S) { 970 VisitOMPLoopBasedDirective(S); 971 } 972 973 void StmtProfiler::VisitOMPTileDirective(const OMPTileDirective *S) { 974 VisitOMPLoopTransformationDirective(S); 975 } 976 977 void StmtProfiler::VisitOMPUnrollDirective(const OMPUnrollDirective *S) { 978 VisitOMPLoopTransformationDirective(S); 979 } 980 981 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { 982 VisitOMPLoopDirective(S); 983 } 984 985 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) { 986 VisitOMPLoopDirective(S); 987 } 988 989 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { 990 VisitOMPExecutableDirective(S); 991 } 992 993 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { 994 VisitOMPExecutableDirective(S); 995 } 996 997 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { 998 VisitOMPExecutableDirective(S); 999 } 1000 1001 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) { 1002 VisitOMPExecutableDirective(S); 1003 } 1004 1005 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { 1006 VisitOMPExecutableDirective(S); 1007 VisitName(S->getDirectiveName().getName()); 1008 } 1009 1010 void 1011 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { 1012 VisitOMPLoopDirective(S); 1013 } 1014 1015 void StmtProfiler::VisitOMPParallelForSimdDirective( 1016 const OMPParallelForSimdDirective *S) { 1017 VisitOMPLoopDirective(S); 1018 } 1019 1020 void StmtProfiler::VisitOMPParallelMasterDirective( 1021 const OMPParallelMasterDirective *S) { 1022 VisitOMPExecutableDirective(S); 1023 } 1024 1025 void StmtProfiler::VisitOMPParallelMaskedDirective( 1026 const OMPParallelMaskedDirective *S) { 1027 VisitOMPExecutableDirective(S); 1028 } 1029 1030 void StmtProfiler::VisitOMPParallelSectionsDirective( 1031 const OMPParallelSectionsDirective *S) { 1032 VisitOMPExecutableDirective(S); 1033 } 1034 1035 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) { 1036 VisitOMPExecutableDirective(S); 1037 } 1038 1039 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) { 1040 VisitOMPExecutableDirective(S); 1041 } 1042 1043 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { 1044 VisitOMPExecutableDirective(S); 1045 } 1046 1047 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { 1048 VisitOMPExecutableDirective(S); 1049 } 1050 1051 void StmtProfiler::VisitOMPErrorDirective(const OMPErrorDirective *S) { 1052 VisitOMPExecutableDirective(S); 1053 } 1054 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) { 1055 VisitOMPExecutableDirective(S); 1056 if (const Expr *E = S->getReductionRef()) 1057 VisitStmt(E); 1058 } 1059 1060 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) { 1061 VisitOMPExecutableDirective(S); 1062 } 1063 1064 void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) { 1065 VisitOMPExecutableDirective(S); 1066 } 1067 1068 void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) { 1069 VisitOMPExecutableDirective(S); 1070 } 1071 1072 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) { 1073 VisitOMPExecutableDirective(S); 1074 } 1075 1076 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) { 1077 VisitOMPExecutableDirective(S); 1078 } 1079 1080 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { 1081 VisitOMPExecutableDirective(S); 1082 } 1083 1084 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) { 1085 VisitOMPExecutableDirective(S); 1086 } 1087 1088 void StmtProfiler::VisitOMPTargetEnterDataDirective( 1089 const OMPTargetEnterDataDirective *S) { 1090 VisitOMPExecutableDirective(S); 1091 } 1092 1093 void StmtProfiler::VisitOMPTargetExitDataDirective( 1094 const OMPTargetExitDataDirective *S) { 1095 VisitOMPExecutableDirective(S); 1096 } 1097 1098 void StmtProfiler::VisitOMPTargetParallelDirective( 1099 const OMPTargetParallelDirective *S) { 1100 VisitOMPExecutableDirective(S); 1101 } 1102 1103 void StmtProfiler::VisitOMPTargetParallelForDirective( 1104 const OMPTargetParallelForDirective *S) { 1105 VisitOMPExecutableDirective(S); 1106 } 1107 1108 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { 1109 VisitOMPExecutableDirective(S); 1110 } 1111 1112 void StmtProfiler::VisitOMPCancellationPointDirective( 1113 const OMPCancellationPointDirective *S) { 1114 VisitOMPExecutableDirective(S); 1115 } 1116 1117 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { 1118 VisitOMPExecutableDirective(S); 1119 } 1120 1121 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) { 1122 VisitOMPLoopDirective(S); 1123 } 1124 1125 void StmtProfiler::VisitOMPTaskLoopSimdDirective( 1126 const OMPTaskLoopSimdDirective *S) { 1127 VisitOMPLoopDirective(S); 1128 } 1129 1130 void StmtProfiler::VisitOMPMasterTaskLoopDirective( 1131 const OMPMasterTaskLoopDirective *S) { 1132 VisitOMPLoopDirective(S); 1133 } 1134 1135 void StmtProfiler::VisitOMPMaskedTaskLoopDirective( 1136 const OMPMaskedTaskLoopDirective *S) { 1137 VisitOMPLoopDirective(S); 1138 } 1139 1140 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective( 1141 const OMPMasterTaskLoopSimdDirective *S) { 1142 VisitOMPLoopDirective(S); 1143 } 1144 1145 void StmtProfiler::VisitOMPMaskedTaskLoopSimdDirective( 1146 const OMPMaskedTaskLoopSimdDirective *S) { 1147 VisitOMPLoopDirective(S); 1148 } 1149 1150 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective( 1151 const OMPParallelMasterTaskLoopDirective *S) { 1152 VisitOMPLoopDirective(S); 1153 } 1154 1155 void StmtProfiler::VisitOMPParallelMaskedTaskLoopDirective( 1156 const OMPParallelMaskedTaskLoopDirective *S) { 1157 VisitOMPLoopDirective(S); 1158 } 1159 1160 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective( 1161 const OMPParallelMasterTaskLoopSimdDirective *S) { 1162 VisitOMPLoopDirective(S); 1163 } 1164 1165 void StmtProfiler::VisitOMPParallelMaskedTaskLoopSimdDirective( 1166 const OMPParallelMaskedTaskLoopSimdDirective *S) { 1167 VisitOMPLoopDirective(S); 1168 } 1169 1170 void StmtProfiler::VisitOMPDistributeDirective( 1171 const OMPDistributeDirective *S) { 1172 VisitOMPLoopDirective(S); 1173 } 1174 1175 void OMPClauseProfiler::VisitOMPDistScheduleClause( 1176 const OMPDistScheduleClause *C) { 1177 VistOMPClauseWithPreInit(C); 1178 if (auto *S = C->getChunkSize()) 1179 Profiler->VisitStmt(S); 1180 } 1181 1182 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {} 1183 1184 void StmtProfiler::VisitOMPTargetUpdateDirective( 1185 const OMPTargetUpdateDirective *S) { 1186 VisitOMPExecutableDirective(S); 1187 } 1188 1189 void StmtProfiler::VisitOMPDistributeParallelForDirective( 1190 const OMPDistributeParallelForDirective *S) { 1191 VisitOMPLoopDirective(S); 1192 } 1193 1194 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective( 1195 const OMPDistributeParallelForSimdDirective *S) { 1196 VisitOMPLoopDirective(S); 1197 } 1198 1199 void StmtProfiler::VisitOMPDistributeSimdDirective( 1200 const OMPDistributeSimdDirective *S) { 1201 VisitOMPLoopDirective(S); 1202 } 1203 1204 void StmtProfiler::VisitOMPTargetParallelForSimdDirective( 1205 const OMPTargetParallelForSimdDirective *S) { 1206 VisitOMPLoopDirective(S); 1207 } 1208 1209 void StmtProfiler::VisitOMPTargetSimdDirective( 1210 const OMPTargetSimdDirective *S) { 1211 VisitOMPLoopDirective(S); 1212 } 1213 1214 void StmtProfiler::VisitOMPTeamsDistributeDirective( 1215 const OMPTeamsDistributeDirective *S) { 1216 VisitOMPLoopDirective(S); 1217 } 1218 1219 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective( 1220 const OMPTeamsDistributeSimdDirective *S) { 1221 VisitOMPLoopDirective(S); 1222 } 1223 1224 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective( 1225 const OMPTeamsDistributeParallelForSimdDirective *S) { 1226 VisitOMPLoopDirective(S); 1227 } 1228 1229 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective( 1230 const OMPTeamsDistributeParallelForDirective *S) { 1231 VisitOMPLoopDirective(S); 1232 } 1233 1234 void StmtProfiler::VisitOMPTargetTeamsDirective( 1235 const OMPTargetTeamsDirective *S) { 1236 VisitOMPExecutableDirective(S); 1237 } 1238 1239 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective( 1240 const OMPTargetTeamsDistributeDirective *S) { 1241 VisitOMPLoopDirective(S); 1242 } 1243 1244 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective( 1245 const OMPTargetTeamsDistributeParallelForDirective *S) { 1246 VisitOMPLoopDirective(S); 1247 } 1248 1249 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective( 1250 const OMPTargetTeamsDistributeParallelForSimdDirective *S) { 1251 VisitOMPLoopDirective(S); 1252 } 1253 1254 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective( 1255 const OMPTargetTeamsDistributeSimdDirective *S) { 1256 VisitOMPLoopDirective(S); 1257 } 1258 1259 void StmtProfiler::VisitOMPInteropDirective(const OMPInteropDirective *S) { 1260 VisitOMPExecutableDirective(S); 1261 } 1262 1263 void StmtProfiler::VisitOMPDispatchDirective(const OMPDispatchDirective *S) { 1264 VisitOMPExecutableDirective(S); 1265 } 1266 1267 void StmtProfiler::VisitOMPMaskedDirective(const OMPMaskedDirective *S) { 1268 VisitOMPExecutableDirective(S); 1269 } 1270 1271 void StmtProfiler::VisitOMPGenericLoopDirective( 1272 const OMPGenericLoopDirective *S) { 1273 VisitOMPLoopDirective(S); 1274 } 1275 1276 void StmtProfiler::VisitOMPTeamsGenericLoopDirective( 1277 const OMPTeamsGenericLoopDirective *S) { 1278 VisitOMPLoopDirective(S); 1279 } 1280 1281 void StmtProfiler::VisitOMPTargetTeamsGenericLoopDirective( 1282 const OMPTargetTeamsGenericLoopDirective *S) { 1283 VisitOMPLoopDirective(S); 1284 } 1285 1286 void StmtProfiler::VisitOMPParallelGenericLoopDirective( 1287 const OMPParallelGenericLoopDirective *S) { 1288 VisitOMPLoopDirective(S); 1289 } 1290 1291 void StmtProfiler::VisitOMPTargetParallelGenericLoopDirective( 1292 const OMPTargetParallelGenericLoopDirective *S) { 1293 VisitOMPLoopDirective(S); 1294 } 1295 1296 void StmtProfiler::VisitExpr(const Expr *S) { 1297 VisitStmt(S); 1298 } 1299 1300 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) { 1301 VisitExpr(S); 1302 } 1303 1304 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 1305 VisitExpr(S); 1306 if (!Canonical) 1307 VisitNestedNameSpecifier(S->getQualifier()); 1308 VisitDecl(S->getDecl()); 1309 if (!Canonical) { 1310 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1311 if (S->hasExplicitTemplateArgs()) 1312 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1313 } 1314 } 1315 1316 void StmtProfiler::VisitSYCLUniqueStableNameExpr( 1317 const SYCLUniqueStableNameExpr *S) { 1318 VisitExpr(S); 1319 VisitType(S->getTypeSourceInfo()->getType()); 1320 } 1321 1322 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { 1323 VisitExpr(S); 1324 ID.AddInteger(S->getIdentKind()); 1325 } 1326 1327 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { 1328 VisitExpr(S); 1329 S->getValue().Profile(ID); 1330 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1331 } 1332 1333 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) { 1334 VisitExpr(S); 1335 S->getValue().Profile(ID); 1336 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1337 } 1338 1339 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { 1340 VisitExpr(S); 1341 ID.AddInteger(S->getKind()); 1342 ID.AddInteger(S->getValue()); 1343 } 1344 1345 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { 1346 VisitExpr(S); 1347 S->getValue().Profile(ID); 1348 ID.AddBoolean(S->isExact()); 1349 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1350 } 1351 1352 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { 1353 VisitExpr(S); 1354 } 1355 1356 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) { 1357 VisitExpr(S); 1358 ID.AddString(S->getBytes()); 1359 ID.AddInteger(S->getKind()); 1360 } 1361 1362 void StmtProfiler::VisitParenExpr(const ParenExpr *S) { 1363 VisitExpr(S); 1364 } 1365 1366 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) { 1367 VisitExpr(S); 1368 } 1369 1370 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) { 1371 VisitExpr(S); 1372 ID.AddInteger(S->getOpcode()); 1373 } 1374 1375 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) { 1376 VisitType(S->getTypeSourceInfo()->getType()); 1377 unsigned n = S->getNumComponents(); 1378 for (unsigned i = 0; i < n; ++i) { 1379 const OffsetOfNode &ON = S->getComponent(i); 1380 ID.AddInteger(ON.getKind()); 1381 switch (ON.getKind()) { 1382 case OffsetOfNode::Array: 1383 // Expressions handled below. 1384 break; 1385 1386 case OffsetOfNode::Field: 1387 VisitDecl(ON.getField()); 1388 break; 1389 1390 case OffsetOfNode::Identifier: 1391 VisitIdentifierInfo(ON.getFieldName()); 1392 break; 1393 1394 case OffsetOfNode::Base: 1395 // These nodes are implicit, and therefore don't need profiling. 1396 break; 1397 } 1398 } 1399 1400 VisitExpr(S); 1401 } 1402 1403 void 1404 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) { 1405 VisitExpr(S); 1406 ID.AddInteger(S->getKind()); 1407 if (S->isArgumentType()) 1408 VisitType(S->getArgumentType()); 1409 } 1410 1411 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) { 1412 VisitExpr(S); 1413 } 1414 1415 void StmtProfiler::VisitMatrixSubscriptExpr(const MatrixSubscriptExpr *S) { 1416 VisitExpr(S); 1417 } 1418 1419 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) { 1420 VisitExpr(S); 1421 } 1422 1423 void StmtProfiler::VisitOMPArrayShapingExpr(const OMPArrayShapingExpr *S) { 1424 VisitExpr(S); 1425 } 1426 1427 void StmtProfiler::VisitOMPIteratorExpr(const OMPIteratorExpr *S) { 1428 VisitExpr(S); 1429 for (unsigned I = 0, E = S->numOfIterators(); I < E; ++I) 1430 VisitDecl(S->getIteratorDecl(I)); 1431 } 1432 1433 void StmtProfiler::VisitCallExpr(const CallExpr *S) { 1434 VisitExpr(S); 1435 } 1436 1437 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) { 1438 VisitExpr(S); 1439 VisitDecl(S->getMemberDecl()); 1440 if (!Canonical) 1441 VisitNestedNameSpecifier(S->getQualifier()); 1442 ID.AddBoolean(S->isArrow()); 1443 } 1444 1445 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) { 1446 VisitExpr(S); 1447 ID.AddBoolean(S->isFileScope()); 1448 } 1449 1450 void StmtProfiler::VisitCastExpr(const CastExpr *S) { 1451 VisitExpr(S); 1452 } 1453 1454 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) { 1455 VisitCastExpr(S); 1456 ID.AddInteger(S->getValueKind()); 1457 } 1458 1459 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) { 1460 VisitCastExpr(S); 1461 VisitType(S->getTypeAsWritten()); 1462 } 1463 1464 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) { 1465 VisitExplicitCastExpr(S); 1466 } 1467 1468 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) { 1469 VisitExpr(S); 1470 ID.AddInteger(S->getOpcode()); 1471 } 1472 1473 void 1474 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) { 1475 VisitBinaryOperator(S); 1476 } 1477 1478 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) { 1479 VisitExpr(S); 1480 } 1481 1482 void StmtProfiler::VisitBinaryConditionalOperator( 1483 const BinaryConditionalOperator *S) { 1484 VisitExpr(S); 1485 } 1486 1487 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) { 1488 VisitExpr(S); 1489 VisitDecl(S->getLabel()); 1490 } 1491 1492 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) { 1493 VisitExpr(S); 1494 } 1495 1496 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) { 1497 VisitExpr(S); 1498 } 1499 1500 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { 1501 VisitExpr(S); 1502 } 1503 1504 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { 1505 VisitExpr(S); 1506 } 1507 1508 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) { 1509 VisitExpr(S); 1510 } 1511 1512 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) { 1513 VisitExpr(S); 1514 } 1515 1516 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) { 1517 if (S->getSyntacticForm()) { 1518 VisitInitListExpr(S->getSyntacticForm()); 1519 return; 1520 } 1521 1522 VisitExpr(S); 1523 } 1524 1525 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) { 1526 VisitExpr(S); 1527 ID.AddBoolean(S->usesGNUSyntax()); 1528 for (const DesignatedInitExpr::Designator &D : S->designators()) { 1529 if (D.isFieldDesignator()) { 1530 ID.AddInteger(0); 1531 VisitName(D.getFieldName()); 1532 continue; 1533 } 1534 1535 if (D.isArrayDesignator()) { 1536 ID.AddInteger(1); 1537 } else { 1538 assert(D.isArrayRangeDesignator()); 1539 ID.AddInteger(2); 1540 } 1541 ID.AddInteger(D.getArrayIndex()); 1542 } 1543 } 1544 1545 // Seems that if VisitInitListExpr() only works on the syntactic form of an 1546 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 1547 void StmtProfiler::VisitDesignatedInitUpdateExpr( 1548 const DesignatedInitUpdateExpr *S) { 1549 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 1550 "initializer"); 1551 } 1552 1553 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) { 1554 VisitExpr(S); 1555 } 1556 1557 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) { 1558 VisitExpr(S); 1559 } 1560 1561 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) { 1562 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 1563 } 1564 1565 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) { 1566 VisitExpr(S); 1567 } 1568 1569 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) { 1570 VisitExpr(S); 1571 VisitName(&S->getAccessor()); 1572 } 1573 1574 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { 1575 VisitExpr(S); 1576 VisitDecl(S->getBlockDecl()); 1577 } 1578 1579 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { 1580 VisitExpr(S); 1581 for (const GenericSelectionExpr::ConstAssociation Assoc : 1582 S->associations()) { 1583 QualType T = Assoc.getType(); 1584 if (T.isNull()) 1585 ID.AddPointer(nullptr); 1586 else 1587 VisitType(T); 1588 VisitExpr(Assoc.getAssociationExpr()); 1589 } 1590 } 1591 1592 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) { 1593 VisitExpr(S); 1594 for (PseudoObjectExpr::const_semantics_iterator 1595 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) 1596 // Normally, we would not profile the source expressions of OVEs. 1597 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i)) 1598 Visit(OVE->getSourceExpr()); 1599 } 1600 1601 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) { 1602 VisitExpr(S); 1603 ID.AddInteger(S->getOp()); 1604 } 1605 1606 void StmtProfiler::VisitConceptSpecializationExpr( 1607 const ConceptSpecializationExpr *S) { 1608 VisitExpr(S); 1609 VisitDecl(S->getNamedConcept()); 1610 for (const TemplateArgument &Arg : S->getTemplateArguments()) 1611 VisitTemplateArgument(Arg); 1612 } 1613 1614 void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) { 1615 VisitExpr(S); 1616 ID.AddInteger(S->getLocalParameters().size()); 1617 for (ParmVarDecl *LocalParam : S->getLocalParameters()) 1618 VisitDecl(LocalParam); 1619 ID.AddInteger(S->getRequirements().size()); 1620 for (concepts::Requirement *Req : S->getRequirements()) { 1621 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) { 1622 ID.AddInteger(concepts::Requirement::RK_Type); 1623 ID.AddBoolean(TypeReq->isSubstitutionFailure()); 1624 if (!TypeReq->isSubstitutionFailure()) 1625 VisitType(TypeReq->getType()->getType()); 1626 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) { 1627 ID.AddInteger(concepts::Requirement::RK_Compound); 1628 ID.AddBoolean(ExprReq->isExprSubstitutionFailure()); 1629 if (!ExprReq->isExprSubstitutionFailure()) 1630 Visit(ExprReq->getExpr()); 1631 // C++2a [expr.prim.req.compound]p1 Example: 1632 // [...] The compound-requirement in C1 requires that x++ is a valid 1633 // expression. It is equivalent to the simple-requirement x++; [...] 1634 // We therefore do not profile isSimple() here. 1635 ID.AddBoolean(ExprReq->getNoexceptLoc().isValid()); 1636 const concepts::ExprRequirement::ReturnTypeRequirement &RetReq = 1637 ExprReq->getReturnTypeRequirement(); 1638 if (RetReq.isEmpty()) { 1639 ID.AddInteger(0); 1640 } else if (RetReq.isTypeConstraint()) { 1641 ID.AddInteger(1); 1642 Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()); 1643 } else { 1644 assert(RetReq.isSubstitutionFailure()); 1645 ID.AddInteger(2); 1646 } 1647 } else { 1648 ID.AddInteger(concepts::Requirement::RK_Nested); 1649 auto *NestedReq = cast<concepts::NestedRequirement>(Req); 1650 ID.AddBoolean(NestedReq->hasInvalidConstraint()); 1651 if (!NestedReq->hasInvalidConstraint()) 1652 Visit(NestedReq->getConstraintExpr()); 1653 } 1654 } 1655 } 1656 1657 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S, 1658 UnaryOperatorKind &UnaryOp, 1659 BinaryOperatorKind &BinaryOp, 1660 unsigned &NumArgs) { 1661 switch (S->getOperator()) { 1662 case OO_None: 1663 case OO_New: 1664 case OO_Delete: 1665 case OO_Array_New: 1666 case OO_Array_Delete: 1667 case OO_Arrow: 1668 case OO_Conditional: 1669 case NUM_OVERLOADED_OPERATORS: 1670 llvm_unreachable("Invalid operator call kind"); 1671 1672 case OO_Plus: 1673 if (NumArgs == 1) { 1674 UnaryOp = UO_Plus; 1675 return Stmt::UnaryOperatorClass; 1676 } 1677 1678 BinaryOp = BO_Add; 1679 return Stmt::BinaryOperatorClass; 1680 1681 case OO_Minus: 1682 if (NumArgs == 1) { 1683 UnaryOp = UO_Minus; 1684 return Stmt::UnaryOperatorClass; 1685 } 1686 1687 BinaryOp = BO_Sub; 1688 return Stmt::BinaryOperatorClass; 1689 1690 case OO_Star: 1691 if (NumArgs == 1) { 1692 UnaryOp = UO_Deref; 1693 return Stmt::UnaryOperatorClass; 1694 } 1695 1696 BinaryOp = BO_Mul; 1697 return Stmt::BinaryOperatorClass; 1698 1699 case OO_Slash: 1700 BinaryOp = BO_Div; 1701 return Stmt::BinaryOperatorClass; 1702 1703 case OO_Percent: 1704 BinaryOp = BO_Rem; 1705 return Stmt::BinaryOperatorClass; 1706 1707 case OO_Caret: 1708 BinaryOp = BO_Xor; 1709 return Stmt::BinaryOperatorClass; 1710 1711 case OO_Amp: 1712 if (NumArgs == 1) { 1713 UnaryOp = UO_AddrOf; 1714 return Stmt::UnaryOperatorClass; 1715 } 1716 1717 BinaryOp = BO_And; 1718 return Stmt::BinaryOperatorClass; 1719 1720 case OO_Pipe: 1721 BinaryOp = BO_Or; 1722 return Stmt::BinaryOperatorClass; 1723 1724 case OO_Tilde: 1725 UnaryOp = UO_Not; 1726 return Stmt::UnaryOperatorClass; 1727 1728 case OO_Exclaim: 1729 UnaryOp = UO_LNot; 1730 return Stmt::UnaryOperatorClass; 1731 1732 case OO_Equal: 1733 BinaryOp = BO_Assign; 1734 return Stmt::BinaryOperatorClass; 1735 1736 case OO_Less: 1737 BinaryOp = BO_LT; 1738 return Stmt::BinaryOperatorClass; 1739 1740 case OO_Greater: 1741 BinaryOp = BO_GT; 1742 return Stmt::BinaryOperatorClass; 1743 1744 case OO_PlusEqual: 1745 BinaryOp = BO_AddAssign; 1746 return Stmt::CompoundAssignOperatorClass; 1747 1748 case OO_MinusEqual: 1749 BinaryOp = BO_SubAssign; 1750 return Stmt::CompoundAssignOperatorClass; 1751 1752 case OO_StarEqual: 1753 BinaryOp = BO_MulAssign; 1754 return Stmt::CompoundAssignOperatorClass; 1755 1756 case OO_SlashEqual: 1757 BinaryOp = BO_DivAssign; 1758 return Stmt::CompoundAssignOperatorClass; 1759 1760 case OO_PercentEqual: 1761 BinaryOp = BO_RemAssign; 1762 return Stmt::CompoundAssignOperatorClass; 1763 1764 case OO_CaretEqual: 1765 BinaryOp = BO_XorAssign; 1766 return Stmt::CompoundAssignOperatorClass; 1767 1768 case OO_AmpEqual: 1769 BinaryOp = BO_AndAssign; 1770 return Stmt::CompoundAssignOperatorClass; 1771 1772 case OO_PipeEqual: 1773 BinaryOp = BO_OrAssign; 1774 return Stmt::CompoundAssignOperatorClass; 1775 1776 case OO_LessLess: 1777 BinaryOp = BO_Shl; 1778 return Stmt::BinaryOperatorClass; 1779 1780 case OO_GreaterGreater: 1781 BinaryOp = BO_Shr; 1782 return Stmt::BinaryOperatorClass; 1783 1784 case OO_LessLessEqual: 1785 BinaryOp = BO_ShlAssign; 1786 return Stmt::CompoundAssignOperatorClass; 1787 1788 case OO_GreaterGreaterEqual: 1789 BinaryOp = BO_ShrAssign; 1790 return Stmt::CompoundAssignOperatorClass; 1791 1792 case OO_EqualEqual: 1793 BinaryOp = BO_EQ; 1794 return Stmt::BinaryOperatorClass; 1795 1796 case OO_ExclaimEqual: 1797 BinaryOp = BO_NE; 1798 return Stmt::BinaryOperatorClass; 1799 1800 case OO_LessEqual: 1801 BinaryOp = BO_LE; 1802 return Stmt::BinaryOperatorClass; 1803 1804 case OO_GreaterEqual: 1805 BinaryOp = BO_GE; 1806 return Stmt::BinaryOperatorClass; 1807 1808 case OO_Spaceship: 1809 BinaryOp = BO_Cmp; 1810 return Stmt::BinaryOperatorClass; 1811 1812 case OO_AmpAmp: 1813 BinaryOp = BO_LAnd; 1814 return Stmt::BinaryOperatorClass; 1815 1816 case OO_PipePipe: 1817 BinaryOp = BO_LOr; 1818 return Stmt::BinaryOperatorClass; 1819 1820 case OO_PlusPlus: 1821 UnaryOp = NumArgs == 1 ? UO_PreInc : UO_PostInc; 1822 NumArgs = 1; 1823 return Stmt::UnaryOperatorClass; 1824 1825 case OO_MinusMinus: 1826 UnaryOp = NumArgs == 1 ? UO_PreDec : UO_PostDec; 1827 NumArgs = 1; 1828 return Stmt::UnaryOperatorClass; 1829 1830 case OO_Comma: 1831 BinaryOp = BO_Comma; 1832 return Stmt::BinaryOperatorClass; 1833 1834 case OO_ArrowStar: 1835 BinaryOp = BO_PtrMemI; 1836 return Stmt::BinaryOperatorClass; 1837 1838 case OO_Subscript: 1839 return Stmt::ArraySubscriptExprClass; 1840 1841 case OO_Call: 1842 return Stmt::CallExprClass; 1843 1844 case OO_Coawait: 1845 UnaryOp = UO_Coawait; 1846 return Stmt::UnaryOperatorClass; 1847 } 1848 1849 llvm_unreachable("Invalid overloaded operator expression"); 1850 } 1851 1852 #if defined(_MSC_VER) && !defined(__clang__) 1853 #if _MSC_VER == 1911 1854 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html 1855 // MSVC 2017 update 3 miscompiles this function, and a clang built with it 1856 // will crash in stage 2 of a bootstrap build. 1857 #pragma optimize("", off) 1858 #endif 1859 #endif 1860 1861 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { 1862 if (S->isTypeDependent()) { 1863 // Type-dependent operator calls are profiled like their underlying 1864 // syntactic operator. 1865 // 1866 // An operator call to operator-> is always implicit, so just skip it. The 1867 // enclosing MemberExpr will profile the actual member access. 1868 if (S->getOperator() == OO_Arrow) 1869 return Visit(S->getArg(0)); 1870 1871 UnaryOperatorKind UnaryOp = UO_Extension; 1872 BinaryOperatorKind BinaryOp = BO_Comma; 1873 unsigned NumArgs = S->getNumArgs(); 1874 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp, NumArgs); 1875 1876 ID.AddInteger(SC); 1877 for (unsigned I = 0; I != NumArgs; ++I) 1878 Visit(S->getArg(I)); 1879 if (SC == Stmt::UnaryOperatorClass) 1880 ID.AddInteger(UnaryOp); 1881 else if (SC == Stmt::BinaryOperatorClass || 1882 SC == Stmt::CompoundAssignOperatorClass) 1883 ID.AddInteger(BinaryOp); 1884 else 1885 assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass); 1886 1887 return; 1888 } 1889 1890 VisitCallExpr(S); 1891 ID.AddInteger(S->getOperator()); 1892 } 1893 1894 void StmtProfiler::VisitCXXRewrittenBinaryOperator( 1895 const CXXRewrittenBinaryOperator *S) { 1896 // If a rewritten operator were ever to be type-dependent, we should profile 1897 // it following its syntactic operator. 1898 assert(!S->isTypeDependent() && 1899 "resolved rewritten operator should never be type-dependent"); 1900 ID.AddBoolean(S->isReversed()); 1901 VisitExpr(S->getSemanticForm()); 1902 } 1903 1904 #if defined(_MSC_VER) && !defined(__clang__) 1905 #if _MSC_VER == 1911 1906 #pragma optimize("", on) 1907 #endif 1908 #endif 1909 1910 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) { 1911 VisitCallExpr(S); 1912 } 1913 1914 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) { 1915 VisitCallExpr(S); 1916 } 1917 1918 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) { 1919 VisitExpr(S); 1920 } 1921 1922 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) { 1923 VisitExplicitCastExpr(S); 1924 } 1925 1926 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) { 1927 VisitCXXNamedCastExpr(S); 1928 } 1929 1930 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) { 1931 VisitCXXNamedCastExpr(S); 1932 } 1933 1934 void 1935 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) { 1936 VisitCXXNamedCastExpr(S); 1937 } 1938 1939 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) { 1940 VisitCXXNamedCastExpr(S); 1941 } 1942 1943 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) { 1944 VisitExpr(S); 1945 VisitType(S->getTypeInfoAsWritten()->getType()); 1946 } 1947 1948 void StmtProfiler::VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr *S) { 1949 VisitCXXNamedCastExpr(S); 1950 } 1951 1952 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) { 1953 VisitCallExpr(S); 1954 } 1955 1956 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) { 1957 VisitExpr(S); 1958 ID.AddBoolean(S->getValue()); 1959 } 1960 1961 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { 1962 VisitExpr(S); 1963 } 1964 1965 void StmtProfiler::VisitCXXStdInitializerListExpr( 1966 const CXXStdInitializerListExpr *S) { 1967 VisitExpr(S); 1968 } 1969 1970 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) { 1971 VisitExpr(S); 1972 if (S->isTypeOperand()) 1973 VisitType(S->getTypeOperandSourceInfo()->getType()); 1974 } 1975 1976 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) { 1977 VisitExpr(S); 1978 if (S->isTypeOperand()) 1979 VisitType(S->getTypeOperandSourceInfo()->getType()); 1980 } 1981 1982 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) { 1983 VisitExpr(S); 1984 VisitDecl(S->getPropertyDecl()); 1985 } 1986 1987 void StmtProfiler::VisitMSPropertySubscriptExpr( 1988 const MSPropertySubscriptExpr *S) { 1989 VisitExpr(S); 1990 } 1991 1992 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) { 1993 VisitExpr(S); 1994 ID.AddBoolean(S->isImplicit()); 1995 } 1996 1997 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) { 1998 VisitExpr(S); 1999 } 2000 2001 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { 2002 VisitExpr(S); 2003 VisitDecl(S->getParam()); 2004 } 2005 2006 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { 2007 VisitExpr(S); 2008 VisitDecl(S->getField()); 2009 } 2010 2011 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) { 2012 VisitExpr(S); 2013 VisitDecl( 2014 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); 2015 } 2016 2017 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) { 2018 VisitExpr(S); 2019 VisitDecl(S->getConstructor()); 2020 ID.AddBoolean(S->isElidable()); 2021 } 2022 2023 void StmtProfiler::VisitCXXInheritedCtorInitExpr( 2024 const CXXInheritedCtorInitExpr *S) { 2025 VisitExpr(S); 2026 VisitDecl(S->getConstructor()); 2027 } 2028 2029 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { 2030 VisitExplicitCastExpr(S); 2031 } 2032 2033 void 2034 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) { 2035 VisitCXXConstructExpr(S); 2036 } 2037 2038 void 2039 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) { 2040 if (!ProfileLambdaExpr) { 2041 // Do not recursively visit the children of this expression. Profiling the 2042 // body would result in unnecessary work, and is not safe to do during 2043 // deserialization. 2044 VisitStmtNoChildren(S); 2045 2046 // C++20 [temp.over.link]p5: 2047 // Two lambda-expressions are never considered equivalent. 2048 VisitDecl(S->getLambdaClass()); 2049 2050 return; 2051 } 2052 2053 CXXRecordDecl *Lambda = S->getLambdaClass(); 2054 ID.AddInteger(Lambda->getODRHash()); 2055 2056 for (const auto &Capture : Lambda->captures()) { 2057 ID.AddInteger(Capture.getCaptureKind()); 2058 if (Capture.capturesVariable()) 2059 VisitDecl(Capture.getCapturedVar()); 2060 } 2061 } 2062 2063 void 2064 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) { 2065 VisitExpr(S); 2066 } 2067 2068 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) { 2069 VisitExpr(S); 2070 ID.AddBoolean(S->isGlobalDelete()); 2071 ID.AddBoolean(S->isArrayForm()); 2072 VisitDecl(S->getOperatorDelete()); 2073 } 2074 2075 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) { 2076 VisitExpr(S); 2077 VisitType(S->getAllocatedType()); 2078 VisitDecl(S->getOperatorNew()); 2079 VisitDecl(S->getOperatorDelete()); 2080 ID.AddBoolean(S->isArray()); 2081 ID.AddInteger(S->getNumPlacementArgs()); 2082 ID.AddBoolean(S->isGlobalNew()); 2083 ID.AddBoolean(S->isParenTypeId()); 2084 ID.AddInteger(S->getInitializationStyle()); 2085 } 2086 2087 void 2088 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { 2089 VisitExpr(S); 2090 ID.AddBoolean(S->isArrow()); 2091 VisitNestedNameSpecifier(S->getQualifier()); 2092 ID.AddBoolean(S->getScopeTypeInfo() != nullptr); 2093 if (S->getScopeTypeInfo()) 2094 VisitType(S->getScopeTypeInfo()->getType()); 2095 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr); 2096 if (S->getDestroyedTypeInfo()) 2097 VisitType(S->getDestroyedType()); 2098 else 2099 VisitIdentifierInfo(S->getDestroyedTypeIdentifier()); 2100 } 2101 2102 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { 2103 VisitExpr(S); 2104 VisitNestedNameSpecifier(S->getQualifier()); 2105 VisitName(S->getName(), /*TreatAsDecl*/ true); 2106 ID.AddBoolean(S->hasExplicitTemplateArgs()); 2107 if (S->hasExplicitTemplateArgs()) 2108 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 2109 } 2110 2111 void 2112 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) { 2113 VisitOverloadExpr(S); 2114 } 2115 2116 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) { 2117 VisitExpr(S); 2118 ID.AddInteger(S->getTrait()); 2119 ID.AddInteger(S->getNumArgs()); 2120 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 2121 VisitType(S->getArg(I)->getType()); 2122 } 2123 2124 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) { 2125 VisitExpr(S); 2126 ID.AddInteger(S->getTrait()); 2127 VisitType(S->getQueriedType()); 2128 } 2129 2130 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) { 2131 VisitExpr(S); 2132 ID.AddInteger(S->getTrait()); 2133 VisitExpr(S->getQueriedExpression()); 2134 } 2135 2136 void StmtProfiler::VisitDependentScopeDeclRefExpr( 2137 const DependentScopeDeclRefExpr *S) { 2138 VisitExpr(S); 2139 VisitName(S->getDeclName()); 2140 VisitNestedNameSpecifier(S->getQualifier()); 2141 ID.AddBoolean(S->hasExplicitTemplateArgs()); 2142 if (S->hasExplicitTemplateArgs()) 2143 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 2144 } 2145 2146 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) { 2147 VisitExpr(S); 2148 } 2149 2150 void StmtProfiler::VisitCXXUnresolvedConstructExpr( 2151 const CXXUnresolvedConstructExpr *S) { 2152 VisitExpr(S); 2153 VisitType(S->getTypeAsWritten()); 2154 ID.AddInteger(S->isListInitialization()); 2155 } 2156 2157 void StmtProfiler::VisitCXXDependentScopeMemberExpr( 2158 const CXXDependentScopeMemberExpr *S) { 2159 ID.AddBoolean(S->isImplicitAccess()); 2160 if (!S->isImplicitAccess()) { 2161 VisitExpr(S); 2162 ID.AddBoolean(S->isArrow()); 2163 } 2164 VisitNestedNameSpecifier(S->getQualifier()); 2165 VisitName(S->getMember()); 2166 ID.AddBoolean(S->hasExplicitTemplateArgs()); 2167 if (S->hasExplicitTemplateArgs()) 2168 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 2169 } 2170 2171 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) { 2172 ID.AddBoolean(S->isImplicitAccess()); 2173 if (!S->isImplicitAccess()) { 2174 VisitExpr(S); 2175 ID.AddBoolean(S->isArrow()); 2176 } 2177 VisitNestedNameSpecifier(S->getQualifier()); 2178 VisitName(S->getMemberName()); 2179 ID.AddBoolean(S->hasExplicitTemplateArgs()); 2180 if (S->hasExplicitTemplateArgs()) 2181 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 2182 } 2183 2184 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) { 2185 VisitExpr(S); 2186 } 2187 2188 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) { 2189 VisitExpr(S); 2190 } 2191 2192 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) { 2193 VisitExpr(S); 2194 VisitDecl(S->getPack()); 2195 if (S->isPartiallySubstituted()) { 2196 auto Args = S->getPartialArguments(); 2197 ID.AddInteger(Args.size()); 2198 for (const auto &TA : Args) 2199 VisitTemplateArgument(TA); 2200 } else { 2201 ID.AddInteger(0); 2202 } 2203 } 2204 2205 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr( 2206 const SubstNonTypeTemplateParmPackExpr *S) { 2207 VisitExpr(S); 2208 VisitDecl(S->getParameterPack()); 2209 VisitTemplateArgument(S->getArgumentPack()); 2210 } 2211 2212 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr( 2213 const SubstNonTypeTemplateParmExpr *E) { 2214 // Profile exactly as the replacement expression. 2215 Visit(E->getReplacement()); 2216 } 2217 2218 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) { 2219 VisitExpr(S); 2220 VisitDecl(S->getParameterPack()); 2221 ID.AddInteger(S->getNumExpansions()); 2222 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I) 2223 VisitDecl(*I); 2224 } 2225 2226 void StmtProfiler::VisitMaterializeTemporaryExpr( 2227 const MaterializeTemporaryExpr *S) { 2228 VisitExpr(S); 2229 } 2230 2231 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) { 2232 VisitExpr(S); 2233 ID.AddInteger(S->getOperator()); 2234 } 2235 2236 void StmtProfiler::VisitCXXParenListInitExpr(const CXXParenListInitExpr *S) { 2237 VisitExpr(S); 2238 } 2239 2240 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) { 2241 VisitStmt(S); 2242 } 2243 2244 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) { 2245 VisitStmt(S); 2246 } 2247 2248 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) { 2249 VisitExpr(S); 2250 } 2251 2252 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) { 2253 VisitExpr(S); 2254 } 2255 2256 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) { 2257 VisitExpr(S); 2258 } 2259 2260 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { 2261 VisitExpr(E); 2262 } 2263 2264 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { 2265 VisitExpr(E); 2266 } 2267 2268 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) { 2269 VisitExpr(E); 2270 } 2271 2272 void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); } 2273 2274 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { 2275 VisitExpr(S); 2276 } 2277 2278 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { 2279 VisitExpr(E); 2280 } 2281 2282 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { 2283 VisitExpr(E); 2284 } 2285 2286 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) { 2287 VisitExpr(E); 2288 } 2289 2290 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) { 2291 VisitExpr(S); 2292 VisitType(S->getEncodedType()); 2293 } 2294 2295 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) { 2296 VisitExpr(S); 2297 VisitName(S->getSelector()); 2298 } 2299 2300 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) { 2301 VisitExpr(S); 2302 VisitDecl(S->getProtocol()); 2303 } 2304 2305 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) { 2306 VisitExpr(S); 2307 VisitDecl(S->getDecl()); 2308 ID.AddBoolean(S->isArrow()); 2309 ID.AddBoolean(S->isFreeIvar()); 2310 } 2311 2312 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) { 2313 VisitExpr(S); 2314 if (S->isImplicitProperty()) { 2315 VisitDecl(S->getImplicitPropertyGetter()); 2316 VisitDecl(S->getImplicitPropertySetter()); 2317 } else { 2318 VisitDecl(S->getExplicitProperty()); 2319 } 2320 if (S->isSuperReceiver()) { 2321 ID.AddBoolean(S->isSuperReceiver()); 2322 VisitType(S->getSuperReceiverType()); 2323 } 2324 } 2325 2326 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) { 2327 VisitExpr(S); 2328 VisitDecl(S->getAtIndexMethodDecl()); 2329 VisitDecl(S->setAtIndexMethodDecl()); 2330 } 2331 2332 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) { 2333 VisitExpr(S); 2334 VisitName(S->getSelector()); 2335 VisitDecl(S->getMethodDecl()); 2336 } 2337 2338 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) { 2339 VisitExpr(S); 2340 ID.AddBoolean(S->isArrow()); 2341 } 2342 2343 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) { 2344 VisitExpr(S); 2345 ID.AddBoolean(S->getValue()); 2346 } 2347 2348 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr( 2349 const ObjCIndirectCopyRestoreExpr *S) { 2350 VisitExpr(S); 2351 ID.AddBoolean(S->shouldCopy()); 2352 } 2353 2354 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) { 2355 VisitExplicitCastExpr(S); 2356 ID.AddBoolean(S->getBridgeKind()); 2357 } 2358 2359 void StmtProfiler::VisitObjCAvailabilityCheckExpr( 2360 const ObjCAvailabilityCheckExpr *S) { 2361 VisitExpr(S); 2362 } 2363 2364 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, 2365 unsigned NumArgs) { 2366 ID.AddInteger(NumArgs); 2367 for (unsigned I = 0; I != NumArgs; ++I) 2368 VisitTemplateArgument(Args[I].getArgument()); 2369 } 2370 2371 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { 2372 // Mostly repetitive with TemplateArgument::Profile! 2373 ID.AddInteger(Arg.getKind()); 2374 switch (Arg.getKind()) { 2375 case TemplateArgument::Null: 2376 break; 2377 2378 case TemplateArgument::Type: 2379 VisitType(Arg.getAsType()); 2380 break; 2381 2382 case TemplateArgument::Template: 2383 case TemplateArgument::TemplateExpansion: 2384 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); 2385 break; 2386 2387 case TemplateArgument::Declaration: 2388 VisitType(Arg.getParamTypeForDecl()); 2389 // FIXME: Do we need to recursively decompose template parameter objects? 2390 VisitDecl(Arg.getAsDecl()); 2391 break; 2392 2393 case TemplateArgument::NullPtr: 2394 VisitType(Arg.getNullPtrType()); 2395 break; 2396 2397 case TemplateArgument::Integral: 2398 VisitType(Arg.getIntegralType()); 2399 Arg.getAsIntegral().Profile(ID); 2400 break; 2401 2402 case TemplateArgument::Expression: 2403 Visit(Arg.getAsExpr()); 2404 break; 2405 2406 case TemplateArgument::Pack: 2407 for (const auto &P : Arg.pack_elements()) 2408 VisitTemplateArgument(P); 2409 break; 2410 } 2411 } 2412 2413 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2414 bool Canonical, bool ProfileLambdaExpr) const { 2415 StmtProfilerWithPointers Profiler(ID, Context, Canonical, ProfileLambdaExpr); 2416 Profiler.Visit(this); 2417 } 2418 2419 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID, 2420 class ODRHash &Hash) const { 2421 StmtProfilerWithoutPointers Profiler(ID, Hash); 2422 Profiler.Visit(this); 2423 } 2424