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