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