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