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 void OMPClauseProfiler::VisitOMPNontemporalClause( 773 const OMPNontemporalClause *C) { 774 VisitOMPClauseList(C); 775 for (auto *E : C->private_refs()) 776 Profiler->VisitStmt(E); 777 } 778 } // namespace 779 780 void 781 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { 782 VisitStmt(S); 783 OMPClauseProfiler P(this); 784 ArrayRef<OMPClause *> Clauses = S->clauses(); 785 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 786 I != E; ++I) 787 if (*I) 788 P.Visit(*I); 789 } 790 791 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { 792 VisitOMPExecutableDirective(S); 793 } 794 795 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { 796 VisitOMPExecutableDirective(S); 797 } 798 799 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { 800 VisitOMPLoopDirective(S); 801 } 802 803 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { 804 VisitOMPLoopDirective(S); 805 } 806 807 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) { 808 VisitOMPLoopDirective(S); 809 } 810 811 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { 812 VisitOMPExecutableDirective(S); 813 } 814 815 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { 816 VisitOMPExecutableDirective(S); 817 } 818 819 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { 820 VisitOMPExecutableDirective(S); 821 } 822 823 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) { 824 VisitOMPExecutableDirective(S); 825 } 826 827 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { 828 VisitOMPExecutableDirective(S); 829 VisitName(S->getDirectiveName().getName()); 830 } 831 832 void 833 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { 834 VisitOMPLoopDirective(S); 835 } 836 837 void StmtProfiler::VisitOMPParallelForSimdDirective( 838 const OMPParallelForSimdDirective *S) { 839 VisitOMPLoopDirective(S); 840 } 841 842 void StmtProfiler::VisitOMPParallelMasterDirective( 843 const OMPParallelMasterDirective *S) { 844 VisitOMPExecutableDirective(S); 845 } 846 847 void StmtProfiler::VisitOMPParallelSectionsDirective( 848 const OMPParallelSectionsDirective *S) { 849 VisitOMPExecutableDirective(S); 850 } 851 852 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) { 853 VisitOMPExecutableDirective(S); 854 } 855 856 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) { 857 VisitOMPExecutableDirective(S); 858 } 859 860 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { 861 VisitOMPExecutableDirective(S); 862 } 863 864 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { 865 VisitOMPExecutableDirective(S); 866 } 867 868 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) { 869 VisitOMPExecutableDirective(S); 870 if (const Expr *E = S->getReductionRef()) 871 VisitStmt(E); 872 } 873 874 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) { 875 VisitOMPExecutableDirective(S); 876 } 877 878 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) { 879 VisitOMPExecutableDirective(S); 880 } 881 882 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) { 883 VisitOMPExecutableDirective(S); 884 } 885 886 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { 887 VisitOMPExecutableDirective(S); 888 } 889 890 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) { 891 VisitOMPExecutableDirective(S); 892 } 893 894 void StmtProfiler::VisitOMPTargetEnterDataDirective( 895 const OMPTargetEnterDataDirective *S) { 896 VisitOMPExecutableDirective(S); 897 } 898 899 void StmtProfiler::VisitOMPTargetExitDataDirective( 900 const OMPTargetExitDataDirective *S) { 901 VisitOMPExecutableDirective(S); 902 } 903 904 void StmtProfiler::VisitOMPTargetParallelDirective( 905 const OMPTargetParallelDirective *S) { 906 VisitOMPExecutableDirective(S); 907 } 908 909 void StmtProfiler::VisitOMPTargetParallelForDirective( 910 const OMPTargetParallelForDirective *S) { 911 VisitOMPExecutableDirective(S); 912 } 913 914 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { 915 VisitOMPExecutableDirective(S); 916 } 917 918 void StmtProfiler::VisitOMPCancellationPointDirective( 919 const OMPCancellationPointDirective *S) { 920 VisitOMPExecutableDirective(S); 921 } 922 923 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { 924 VisitOMPExecutableDirective(S); 925 } 926 927 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) { 928 VisitOMPLoopDirective(S); 929 } 930 931 void StmtProfiler::VisitOMPTaskLoopSimdDirective( 932 const OMPTaskLoopSimdDirective *S) { 933 VisitOMPLoopDirective(S); 934 } 935 936 void StmtProfiler::VisitOMPMasterTaskLoopDirective( 937 const OMPMasterTaskLoopDirective *S) { 938 VisitOMPLoopDirective(S); 939 } 940 941 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective( 942 const OMPMasterTaskLoopSimdDirective *S) { 943 VisitOMPLoopDirective(S); 944 } 945 946 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective( 947 const OMPParallelMasterTaskLoopDirective *S) { 948 VisitOMPLoopDirective(S); 949 } 950 951 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective( 952 const OMPParallelMasterTaskLoopSimdDirective *S) { 953 VisitOMPLoopDirective(S); 954 } 955 956 void StmtProfiler::VisitOMPDistributeDirective( 957 const OMPDistributeDirective *S) { 958 VisitOMPLoopDirective(S); 959 } 960 961 void OMPClauseProfiler::VisitOMPDistScheduleClause( 962 const OMPDistScheduleClause *C) { 963 VistOMPClauseWithPreInit(C); 964 if (auto *S = C->getChunkSize()) 965 Profiler->VisitStmt(S); 966 } 967 968 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {} 969 970 void StmtProfiler::VisitOMPTargetUpdateDirective( 971 const OMPTargetUpdateDirective *S) { 972 VisitOMPExecutableDirective(S); 973 } 974 975 void StmtProfiler::VisitOMPDistributeParallelForDirective( 976 const OMPDistributeParallelForDirective *S) { 977 VisitOMPLoopDirective(S); 978 } 979 980 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective( 981 const OMPDistributeParallelForSimdDirective *S) { 982 VisitOMPLoopDirective(S); 983 } 984 985 void StmtProfiler::VisitOMPDistributeSimdDirective( 986 const OMPDistributeSimdDirective *S) { 987 VisitOMPLoopDirective(S); 988 } 989 990 void StmtProfiler::VisitOMPTargetParallelForSimdDirective( 991 const OMPTargetParallelForSimdDirective *S) { 992 VisitOMPLoopDirective(S); 993 } 994 995 void StmtProfiler::VisitOMPTargetSimdDirective( 996 const OMPTargetSimdDirective *S) { 997 VisitOMPLoopDirective(S); 998 } 999 1000 void StmtProfiler::VisitOMPTeamsDistributeDirective( 1001 const OMPTeamsDistributeDirective *S) { 1002 VisitOMPLoopDirective(S); 1003 } 1004 1005 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective( 1006 const OMPTeamsDistributeSimdDirective *S) { 1007 VisitOMPLoopDirective(S); 1008 } 1009 1010 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective( 1011 const OMPTeamsDistributeParallelForSimdDirective *S) { 1012 VisitOMPLoopDirective(S); 1013 } 1014 1015 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective( 1016 const OMPTeamsDistributeParallelForDirective *S) { 1017 VisitOMPLoopDirective(S); 1018 } 1019 1020 void StmtProfiler::VisitOMPTargetTeamsDirective( 1021 const OMPTargetTeamsDirective *S) { 1022 VisitOMPExecutableDirective(S); 1023 } 1024 1025 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective( 1026 const OMPTargetTeamsDistributeDirective *S) { 1027 VisitOMPLoopDirective(S); 1028 } 1029 1030 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective( 1031 const OMPTargetTeamsDistributeParallelForDirective *S) { 1032 VisitOMPLoopDirective(S); 1033 } 1034 1035 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective( 1036 const OMPTargetTeamsDistributeParallelForSimdDirective *S) { 1037 VisitOMPLoopDirective(S); 1038 } 1039 1040 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective( 1041 const OMPTargetTeamsDistributeSimdDirective *S) { 1042 VisitOMPLoopDirective(S); 1043 } 1044 1045 void StmtProfiler::VisitExpr(const Expr *S) { 1046 VisitStmt(S); 1047 } 1048 1049 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) { 1050 VisitExpr(S); 1051 } 1052 1053 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 1054 VisitExpr(S); 1055 if (!Canonical) 1056 VisitNestedNameSpecifier(S->getQualifier()); 1057 VisitDecl(S->getDecl()); 1058 if (!Canonical) { 1059 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1060 if (S->hasExplicitTemplateArgs()) 1061 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1062 } 1063 } 1064 1065 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { 1066 VisitExpr(S); 1067 ID.AddInteger(S->getIdentKind()); 1068 } 1069 1070 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { 1071 VisitExpr(S); 1072 S->getValue().Profile(ID); 1073 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1074 } 1075 1076 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) { 1077 VisitExpr(S); 1078 S->getValue().Profile(ID); 1079 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1080 } 1081 1082 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { 1083 VisitExpr(S); 1084 ID.AddInteger(S->getKind()); 1085 ID.AddInteger(S->getValue()); 1086 } 1087 1088 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { 1089 VisitExpr(S); 1090 S->getValue().Profile(ID); 1091 ID.AddBoolean(S->isExact()); 1092 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1093 } 1094 1095 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { 1096 VisitExpr(S); 1097 } 1098 1099 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) { 1100 VisitExpr(S); 1101 ID.AddString(S->getBytes()); 1102 ID.AddInteger(S->getKind()); 1103 } 1104 1105 void StmtProfiler::VisitParenExpr(const ParenExpr *S) { 1106 VisitExpr(S); 1107 } 1108 1109 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) { 1110 VisitExpr(S); 1111 } 1112 1113 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) { 1114 VisitExpr(S); 1115 ID.AddInteger(S->getOpcode()); 1116 } 1117 1118 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) { 1119 VisitType(S->getTypeSourceInfo()->getType()); 1120 unsigned n = S->getNumComponents(); 1121 for (unsigned i = 0; i < n; ++i) { 1122 const OffsetOfNode &ON = S->getComponent(i); 1123 ID.AddInteger(ON.getKind()); 1124 switch (ON.getKind()) { 1125 case OffsetOfNode::Array: 1126 // Expressions handled below. 1127 break; 1128 1129 case OffsetOfNode::Field: 1130 VisitDecl(ON.getField()); 1131 break; 1132 1133 case OffsetOfNode::Identifier: 1134 VisitIdentifierInfo(ON.getFieldName()); 1135 break; 1136 1137 case OffsetOfNode::Base: 1138 // These nodes are implicit, and therefore don't need profiling. 1139 break; 1140 } 1141 } 1142 1143 VisitExpr(S); 1144 } 1145 1146 void 1147 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) { 1148 VisitExpr(S); 1149 ID.AddInteger(S->getKind()); 1150 if (S->isArgumentType()) 1151 VisitType(S->getArgumentType()); 1152 } 1153 1154 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) { 1155 VisitExpr(S); 1156 } 1157 1158 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) { 1159 VisitExpr(S); 1160 } 1161 1162 void StmtProfiler::VisitCallExpr(const CallExpr *S) { 1163 VisitExpr(S); 1164 } 1165 1166 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) { 1167 VisitExpr(S); 1168 VisitDecl(S->getMemberDecl()); 1169 if (!Canonical) 1170 VisitNestedNameSpecifier(S->getQualifier()); 1171 ID.AddBoolean(S->isArrow()); 1172 } 1173 1174 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) { 1175 VisitExpr(S); 1176 ID.AddBoolean(S->isFileScope()); 1177 } 1178 1179 void StmtProfiler::VisitCastExpr(const CastExpr *S) { 1180 VisitExpr(S); 1181 } 1182 1183 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) { 1184 VisitCastExpr(S); 1185 ID.AddInteger(S->getValueKind()); 1186 } 1187 1188 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) { 1189 VisitCastExpr(S); 1190 VisitType(S->getTypeAsWritten()); 1191 } 1192 1193 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) { 1194 VisitExplicitCastExpr(S); 1195 } 1196 1197 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) { 1198 VisitExpr(S); 1199 ID.AddInteger(S->getOpcode()); 1200 } 1201 1202 void 1203 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) { 1204 VisitBinaryOperator(S); 1205 } 1206 1207 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) { 1208 VisitExpr(S); 1209 } 1210 1211 void StmtProfiler::VisitBinaryConditionalOperator( 1212 const BinaryConditionalOperator *S) { 1213 VisitExpr(S); 1214 } 1215 1216 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) { 1217 VisitExpr(S); 1218 VisitDecl(S->getLabel()); 1219 } 1220 1221 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) { 1222 VisitExpr(S); 1223 } 1224 1225 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) { 1226 VisitExpr(S); 1227 } 1228 1229 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { 1230 VisitExpr(S); 1231 } 1232 1233 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { 1234 VisitExpr(S); 1235 } 1236 1237 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) { 1238 VisitExpr(S); 1239 } 1240 1241 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) { 1242 VisitExpr(S); 1243 } 1244 1245 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) { 1246 if (S->getSyntacticForm()) { 1247 VisitInitListExpr(S->getSyntacticForm()); 1248 return; 1249 } 1250 1251 VisitExpr(S); 1252 } 1253 1254 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) { 1255 VisitExpr(S); 1256 ID.AddBoolean(S->usesGNUSyntax()); 1257 for (const DesignatedInitExpr::Designator &D : S->designators()) { 1258 if (D.isFieldDesignator()) { 1259 ID.AddInteger(0); 1260 VisitName(D.getFieldName()); 1261 continue; 1262 } 1263 1264 if (D.isArrayDesignator()) { 1265 ID.AddInteger(1); 1266 } else { 1267 assert(D.isArrayRangeDesignator()); 1268 ID.AddInteger(2); 1269 } 1270 ID.AddInteger(D.getFirstExprIndex()); 1271 } 1272 } 1273 1274 // Seems that if VisitInitListExpr() only works on the syntactic form of an 1275 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 1276 void StmtProfiler::VisitDesignatedInitUpdateExpr( 1277 const DesignatedInitUpdateExpr *S) { 1278 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 1279 "initializer"); 1280 } 1281 1282 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) { 1283 VisitExpr(S); 1284 } 1285 1286 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) { 1287 VisitExpr(S); 1288 } 1289 1290 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) { 1291 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 1292 } 1293 1294 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) { 1295 VisitExpr(S); 1296 } 1297 1298 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) { 1299 VisitExpr(S); 1300 VisitName(&S->getAccessor()); 1301 } 1302 1303 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { 1304 VisitExpr(S); 1305 VisitDecl(S->getBlockDecl()); 1306 } 1307 1308 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { 1309 VisitExpr(S); 1310 for (const GenericSelectionExpr::ConstAssociation Assoc : 1311 S->associations()) { 1312 QualType T = Assoc.getType(); 1313 if (T.isNull()) 1314 ID.AddPointer(nullptr); 1315 else 1316 VisitType(T); 1317 VisitExpr(Assoc.getAssociationExpr()); 1318 } 1319 } 1320 1321 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) { 1322 VisitExpr(S); 1323 for (PseudoObjectExpr::const_semantics_iterator 1324 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) 1325 // Normally, we would not profile the source expressions of OVEs. 1326 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i)) 1327 Visit(OVE->getSourceExpr()); 1328 } 1329 1330 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) { 1331 VisitExpr(S); 1332 ID.AddInteger(S->getOp()); 1333 } 1334 1335 void StmtProfiler::VisitConceptSpecializationExpr( 1336 const ConceptSpecializationExpr *S) { 1337 VisitExpr(S); 1338 VisitDecl(S->getFoundDecl()); 1339 VisitTemplateArguments(S->getTemplateArgsAsWritten()->getTemplateArgs(), 1340 S->getTemplateArgsAsWritten()->NumTemplateArgs); 1341 } 1342 1343 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S, 1344 UnaryOperatorKind &UnaryOp, 1345 BinaryOperatorKind &BinaryOp) { 1346 switch (S->getOperator()) { 1347 case OO_None: 1348 case OO_New: 1349 case OO_Delete: 1350 case OO_Array_New: 1351 case OO_Array_Delete: 1352 case OO_Arrow: 1353 case OO_Call: 1354 case OO_Conditional: 1355 case NUM_OVERLOADED_OPERATORS: 1356 llvm_unreachable("Invalid operator call kind"); 1357 1358 case OO_Plus: 1359 if (S->getNumArgs() == 1) { 1360 UnaryOp = UO_Plus; 1361 return Stmt::UnaryOperatorClass; 1362 } 1363 1364 BinaryOp = BO_Add; 1365 return Stmt::BinaryOperatorClass; 1366 1367 case OO_Minus: 1368 if (S->getNumArgs() == 1) { 1369 UnaryOp = UO_Minus; 1370 return Stmt::UnaryOperatorClass; 1371 } 1372 1373 BinaryOp = BO_Sub; 1374 return Stmt::BinaryOperatorClass; 1375 1376 case OO_Star: 1377 if (S->getNumArgs() == 1) { 1378 UnaryOp = UO_Deref; 1379 return Stmt::UnaryOperatorClass; 1380 } 1381 1382 BinaryOp = BO_Mul; 1383 return Stmt::BinaryOperatorClass; 1384 1385 case OO_Slash: 1386 BinaryOp = BO_Div; 1387 return Stmt::BinaryOperatorClass; 1388 1389 case OO_Percent: 1390 BinaryOp = BO_Rem; 1391 return Stmt::BinaryOperatorClass; 1392 1393 case OO_Caret: 1394 BinaryOp = BO_Xor; 1395 return Stmt::BinaryOperatorClass; 1396 1397 case OO_Amp: 1398 if (S->getNumArgs() == 1) { 1399 UnaryOp = UO_AddrOf; 1400 return Stmt::UnaryOperatorClass; 1401 } 1402 1403 BinaryOp = BO_And; 1404 return Stmt::BinaryOperatorClass; 1405 1406 case OO_Pipe: 1407 BinaryOp = BO_Or; 1408 return Stmt::BinaryOperatorClass; 1409 1410 case OO_Tilde: 1411 UnaryOp = UO_Not; 1412 return Stmt::UnaryOperatorClass; 1413 1414 case OO_Exclaim: 1415 UnaryOp = UO_LNot; 1416 return Stmt::UnaryOperatorClass; 1417 1418 case OO_Equal: 1419 BinaryOp = BO_Assign; 1420 return Stmt::BinaryOperatorClass; 1421 1422 case OO_Less: 1423 BinaryOp = BO_LT; 1424 return Stmt::BinaryOperatorClass; 1425 1426 case OO_Greater: 1427 BinaryOp = BO_GT; 1428 return Stmt::BinaryOperatorClass; 1429 1430 case OO_PlusEqual: 1431 BinaryOp = BO_AddAssign; 1432 return Stmt::CompoundAssignOperatorClass; 1433 1434 case OO_MinusEqual: 1435 BinaryOp = BO_SubAssign; 1436 return Stmt::CompoundAssignOperatorClass; 1437 1438 case OO_StarEqual: 1439 BinaryOp = BO_MulAssign; 1440 return Stmt::CompoundAssignOperatorClass; 1441 1442 case OO_SlashEqual: 1443 BinaryOp = BO_DivAssign; 1444 return Stmt::CompoundAssignOperatorClass; 1445 1446 case OO_PercentEqual: 1447 BinaryOp = BO_RemAssign; 1448 return Stmt::CompoundAssignOperatorClass; 1449 1450 case OO_CaretEqual: 1451 BinaryOp = BO_XorAssign; 1452 return Stmt::CompoundAssignOperatorClass; 1453 1454 case OO_AmpEqual: 1455 BinaryOp = BO_AndAssign; 1456 return Stmt::CompoundAssignOperatorClass; 1457 1458 case OO_PipeEqual: 1459 BinaryOp = BO_OrAssign; 1460 return Stmt::CompoundAssignOperatorClass; 1461 1462 case OO_LessLess: 1463 BinaryOp = BO_Shl; 1464 return Stmt::BinaryOperatorClass; 1465 1466 case OO_GreaterGreater: 1467 BinaryOp = BO_Shr; 1468 return Stmt::BinaryOperatorClass; 1469 1470 case OO_LessLessEqual: 1471 BinaryOp = BO_ShlAssign; 1472 return Stmt::CompoundAssignOperatorClass; 1473 1474 case OO_GreaterGreaterEqual: 1475 BinaryOp = BO_ShrAssign; 1476 return Stmt::CompoundAssignOperatorClass; 1477 1478 case OO_EqualEqual: 1479 BinaryOp = BO_EQ; 1480 return Stmt::BinaryOperatorClass; 1481 1482 case OO_ExclaimEqual: 1483 BinaryOp = BO_NE; 1484 return Stmt::BinaryOperatorClass; 1485 1486 case OO_LessEqual: 1487 BinaryOp = BO_LE; 1488 return Stmt::BinaryOperatorClass; 1489 1490 case OO_GreaterEqual: 1491 BinaryOp = BO_GE; 1492 return Stmt::BinaryOperatorClass; 1493 1494 case OO_Spaceship: 1495 // FIXME: Update this once we support <=> expressions. 1496 llvm_unreachable("<=> expressions not supported yet"); 1497 1498 case OO_AmpAmp: 1499 BinaryOp = BO_LAnd; 1500 return Stmt::BinaryOperatorClass; 1501 1502 case OO_PipePipe: 1503 BinaryOp = BO_LOr; 1504 return Stmt::BinaryOperatorClass; 1505 1506 case OO_PlusPlus: 1507 UnaryOp = S->getNumArgs() == 1? UO_PreInc 1508 : UO_PostInc; 1509 return Stmt::UnaryOperatorClass; 1510 1511 case OO_MinusMinus: 1512 UnaryOp = S->getNumArgs() == 1? UO_PreDec 1513 : UO_PostDec; 1514 return Stmt::UnaryOperatorClass; 1515 1516 case OO_Comma: 1517 BinaryOp = BO_Comma; 1518 return Stmt::BinaryOperatorClass; 1519 1520 case OO_ArrowStar: 1521 BinaryOp = BO_PtrMemI; 1522 return Stmt::BinaryOperatorClass; 1523 1524 case OO_Subscript: 1525 return Stmt::ArraySubscriptExprClass; 1526 1527 case OO_Coawait: 1528 UnaryOp = UO_Coawait; 1529 return Stmt::UnaryOperatorClass; 1530 } 1531 1532 llvm_unreachable("Invalid overloaded operator expression"); 1533 } 1534 1535 #if defined(_MSC_VER) && !defined(__clang__) 1536 #if _MSC_VER == 1911 1537 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html 1538 // MSVC 2017 update 3 miscompiles this function, and a clang built with it 1539 // will crash in stage 2 of a bootstrap build. 1540 #pragma optimize("", off) 1541 #endif 1542 #endif 1543 1544 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { 1545 if (S->isTypeDependent()) { 1546 // Type-dependent operator calls are profiled like their underlying 1547 // syntactic operator. 1548 // 1549 // An operator call to operator-> is always implicit, so just skip it. The 1550 // enclosing MemberExpr will profile the actual member access. 1551 if (S->getOperator() == OO_Arrow) 1552 return Visit(S->getArg(0)); 1553 1554 UnaryOperatorKind UnaryOp = UO_Extension; 1555 BinaryOperatorKind BinaryOp = BO_Comma; 1556 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); 1557 1558 ID.AddInteger(SC); 1559 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1560 Visit(S->getArg(I)); 1561 if (SC == Stmt::UnaryOperatorClass) 1562 ID.AddInteger(UnaryOp); 1563 else if (SC == Stmt::BinaryOperatorClass || 1564 SC == Stmt::CompoundAssignOperatorClass) 1565 ID.AddInteger(BinaryOp); 1566 else 1567 assert(SC == Stmt::ArraySubscriptExprClass); 1568 1569 return; 1570 } 1571 1572 VisitCallExpr(S); 1573 ID.AddInteger(S->getOperator()); 1574 } 1575 1576 void StmtProfiler::VisitCXXRewrittenBinaryOperator( 1577 const CXXRewrittenBinaryOperator *S) { 1578 // If a rewritten operator were ever to be type-dependent, we should profile 1579 // it following its syntactic operator. 1580 assert(!S->isTypeDependent() && 1581 "resolved rewritten operator should never be type-dependent"); 1582 ID.AddBoolean(S->isReversed()); 1583 VisitExpr(S->getSemanticForm()); 1584 } 1585 1586 #if defined(_MSC_VER) && !defined(__clang__) 1587 #if _MSC_VER == 1911 1588 #pragma optimize("", on) 1589 #endif 1590 #endif 1591 1592 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) { 1593 VisitCallExpr(S); 1594 } 1595 1596 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) { 1597 VisitCallExpr(S); 1598 } 1599 1600 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) { 1601 VisitExpr(S); 1602 } 1603 1604 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) { 1605 VisitExplicitCastExpr(S); 1606 } 1607 1608 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) { 1609 VisitCXXNamedCastExpr(S); 1610 } 1611 1612 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) { 1613 VisitCXXNamedCastExpr(S); 1614 } 1615 1616 void 1617 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) { 1618 VisitCXXNamedCastExpr(S); 1619 } 1620 1621 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) { 1622 VisitCXXNamedCastExpr(S); 1623 } 1624 1625 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) { 1626 VisitExpr(S); 1627 VisitType(S->getTypeInfoAsWritten()->getType()); 1628 } 1629 1630 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) { 1631 VisitCallExpr(S); 1632 } 1633 1634 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) { 1635 VisitExpr(S); 1636 ID.AddBoolean(S->getValue()); 1637 } 1638 1639 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { 1640 VisitExpr(S); 1641 } 1642 1643 void StmtProfiler::VisitCXXStdInitializerListExpr( 1644 const CXXStdInitializerListExpr *S) { 1645 VisitExpr(S); 1646 } 1647 1648 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) { 1649 VisitExpr(S); 1650 if (S->isTypeOperand()) 1651 VisitType(S->getTypeOperandSourceInfo()->getType()); 1652 } 1653 1654 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) { 1655 VisitExpr(S); 1656 if (S->isTypeOperand()) 1657 VisitType(S->getTypeOperandSourceInfo()->getType()); 1658 } 1659 1660 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) { 1661 VisitExpr(S); 1662 VisitDecl(S->getPropertyDecl()); 1663 } 1664 1665 void StmtProfiler::VisitMSPropertySubscriptExpr( 1666 const MSPropertySubscriptExpr *S) { 1667 VisitExpr(S); 1668 } 1669 1670 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) { 1671 VisitExpr(S); 1672 ID.AddBoolean(S->isImplicit()); 1673 } 1674 1675 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) { 1676 VisitExpr(S); 1677 } 1678 1679 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { 1680 VisitExpr(S); 1681 VisitDecl(S->getParam()); 1682 } 1683 1684 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { 1685 VisitExpr(S); 1686 VisitDecl(S->getField()); 1687 } 1688 1689 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) { 1690 VisitExpr(S); 1691 VisitDecl( 1692 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); 1693 } 1694 1695 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) { 1696 VisitExpr(S); 1697 VisitDecl(S->getConstructor()); 1698 ID.AddBoolean(S->isElidable()); 1699 } 1700 1701 void StmtProfiler::VisitCXXInheritedCtorInitExpr( 1702 const CXXInheritedCtorInitExpr *S) { 1703 VisitExpr(S); 1704 VisitDecl(S->getConstructor()); 1705 } 1706 1707 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { 1708 VisitExplicitCastExpr(S); 1709 } 1710 1711 void 1712 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) { 1713 VisitCXXConstructExpr(S); 1714 } 1715 1716 void 1717 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) { 1718 VisitExpr(S); 1719 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), 1720 CEnd = S->explicit_capture_end(); 1721 C != CEnd; ++C) { 1722 if (C->capturesVLAType()) 1723 continue; 1724 1725 ID.AddInteger(C->getCaptureKind()); 1726 switch (C->getCaptureKind()) { 1727 case LCK_StarThis: 1728 case LCK_This: 1729 break; 1730 case LCK_ByRef: 1731 case LCK_ByCopy: 1732 VisitDecl(C->getCapturedVar()); 1733 ID.AddBoolean(C->isPackExpansion()); 1734 break; 1735 case LCK_VLAType: 1736 llvm_unreachable("VLA type in explicit captures."); 1737 } 1738 } 1739 // Note: If we actually needed to be able to match lambda 1740 // expressions, we would have to consider parameters and return type 1741 // here, among other things. 1742 VisitStmt(S->getBody()); 1743 } 1744 1745 void 1746 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) { 1747 VisitExpr(S); 1748 } 1749 1750 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) { 1751 VisitExpr(S); 1752 ID.AddBoolean(S->isGlobalDelete()); 1753 ID.AddBoolean(S->isArrayForm()); 1754 VisitDecl(S->getOperatorDelete()); 1755 } 1756 1757 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) { 1758 VisitExpr(S); 1759 VisitType(S->getAllocatedType()); 1760 VisitDecl(S->getOperatorNew()); 1761 VisitDecl(S->getOperatorDelete()); 1762 ID.AddBoolean(S->isArray()); 1763 ID.AddInteger(S->getNumPlacementArgs()); 1764 ID.AddBoolean(S->isGlobalNew()); 1765 ID.AddBoolean(S->isParenTypeId()); 1766 ID.AddInteger(S->getInitializationStyle()); 1767 } 1768 1769 void 1770 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { 1771 VisitExpr(S); 1772 ID.AddBoolean(S->isArrow()); 1773 VisitNestedNameSpecifier(S->getQualifier()); 1774 ID.AddBoolean(S->getScopeTypeInfo() != nullptr); 1775 if (S->getScopeTypeInfo()) 1776 VisitType(S->getScopeTypeInfo()->getType()); 1777 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr); 1778 if (S->getDestroyedTypeInfo()) 1779 VisitType(S->getDestroyedType()); 1780 else 1781 VisitIdentifierInfo(S->getDestroyedTypeIdentifier()); 1782 } 1783 1784 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { 1785 VisitExpr(S); 1786 VisitNestedNameSpecifier(S->getQualifier()); 1787 VisitName(S->getName(), /*TreatAsDecl*/ true); 1788 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1789 if (S->hasExplicitTemplateArgs()) 1790 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1791 } 1792 1793 void 1794 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) { 1795 VisitOverloadExpr(S); 1796 } 1797 1798 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) { 1799 VisitExpr(S); 1800 ID.AddInteger(S->getTrait()); 1801 ID.AddInteger(S->getNumArgs()); 1802 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1803 VisitType(S->getArg(I)->getType()); 1804 } 1805 1806 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) { 1807 VisitExpr(S); 1808 ID.AddInteger(S->getTrait()); 1809 VisitType(S->getQueriedType()); 1810 } 1811 1812 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) { 1813 VisitExpr(S); 1814 ID.AddInteger(S->getTrait()); 1815 VisitExpr(S->getQueriedExpression()); 1816 } 1817 1818 void StmtProfiler::VisitDependentScopeDeclRefExpr( 1819 const DependentScopeDeclRefExpr *S) { 1820 VisitExpr(S); 1821 VisitName(S->getDeclName()); 1822 VisitNestedNameSpecifier(S->getQualifier()); 1823 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1824 if (S->hasExplicitTemplateArgs()) 1825 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1826 } 1827 1828 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) { 1829 VisitExpr(S); 1830 } 1831 1832 void StmtProfiler::VisitCXXUnresolvedConstructExpr( 1833 const CXXUnresolvedConstructExpr *S) { 1834 VisitExpr(S); 1835 VisitType(S->getTypeAsWritten()); 1836 ID.AddInteger(S->isListInitialization()); 1837 } 1838 1839 void StmtProfiler::VisitCXXDependentScopeMemberExpr( 1840 const CXXDependentScopeMemberExpr *S) { 1841 ID.AddBoolean(S->isImplicitAccess()); 1842 if (!S->isImplicitAccess()) { 1843 VisitExpr(S); 1844 ID.AddBoolean(S->isArrow()); 1845 } 1846 VisitNestedNameSpecifier(S->getQualifier()); 1847 VisitName(S->getMember()); 1848 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1849 if (S->hasExplicitTemplateArgs()) 1850 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1851 } 1852 1853 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) { 1854 ID.AddBoolean(S->isImplicitAccess()); 1855 if (!S->isImplicitAccess()) { 1856 VisitExpr(S); 1857 ID.AddBoolean(S->isArrow()); 1858 } 1859 VisitNestedNameSpecifier(S->getQualifier()); 1860 VisitName(S->getMemberName()); 1861 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1862 if (S->hasExplicitTemplateArgs()) 1863 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1864 } 1865 1866 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) { 1867 VisitExpr(S); 1868 } 1869 1870 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) { 1871 VisitExpr(S); 1872 } 1873 1874 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) { 1875 VisitExpr(S); 1876 VisitDecl(S->getPack()); 1877 if (S->isPartiallySubstituted()) { 1878 auto Args = S->getPartialArguments(); 1879 ID.AddInteger(Args.size()); 1880 for (const auto &TA : Args) 1881 VisitTemplateArgument(TA); 1882 } else { 1883 ID.AddInteger(0); 1884 } 1885 } 1886 1887 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr( 1888 const SubstNonTypeTemplateParmPackExpr *S) { 1889 VisitExpr(S); 1890 VisitDecl(S->getParameterPack()); 1891 VisitTemplateArgument(S->getArgumentPack()); 1892 } 1893 1894 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr( 1895 const SubstNonTypeTemplateParmExpr *E) { 1896 // Profile exactly as the replacement expression. 1897 Visit(E->getReplacement()); 1898 } 1899 1900 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) { 1901 VisitExpr(S); 1902 VisitDecl(S->getParameterPack()); 1903 ID.AddInteger(S->getNumExpansions()); 1904 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I) 1905 VisitDecl(*I); 1906 } 1907 1908 void StmtProfiler::VisitMaterializeTemporaryExpr( 1909 const MaterializeTemporaryExpr *S) { 1910 VisitExpr(S); 1911 } 1912 1913 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) { 1914 VisitExpr(S); 1915 ID.AddInteger(S->getOperator()); 1916 } 1917 1918 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) { 1919 VisitStmt(S); 1920 } 1921 1922 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) { 1923 VisitStmt(S); 1924 } 1925 1926 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) { 1927 VisitExpr(S); 1928 } 1929 1930 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) { 1931 VisitExpr(S); 1932 } 1933 1934 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) { 1935 VisitExpr(S); 1936 } 1937 1938 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { 1939 VisitExpr(E); 1940 } 1941 1942 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { 1943 VisitExpr(E); 1944 } 1945 1946 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) { 1947 VisitExpr(E); 1948 } 1949 1950 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { 1951 VisitExpr(S); 1952 } 1953 1954 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { 1955 VisitExpr(E); 1956 } 1957 1958 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { 1959 VisitExpr(E); 1960 } 1961 1962 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) { 1963 VisitExpr(E); 1964 } 1965 1966 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) { 1967 VisitExpr(S); 1968 VisitType(S->getEncodedType()); 1969 } 1970 1971 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) { 1972 VisitExpr(S); 1973 VisitName(S->getSelector()); 1974 } 1975 1976 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) { 1977 VisitExpr(S); 1978 VisitDecl(S->getProtocol()); 1979 } 1980 1981 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) { 1982 VisitExpr(S); 1983 VisitDecl(S->getDecl()); 1984 ID.AddBoolean(S->isArrow()); 1985 ID.AddBoolean(S->isFreeIvar()); 1986 } 1987 1988 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) { 1989 VisitExpr(S); 1990 if (S->isImplicitProperty()) { 1991 VisitDecl(S->getImplicitPropertyGetter()); 1992 VisitDecl(S->getImplicitPropertySetter()); 1993 } else { 1994 VisitDecl(S->getExplicitProperty()); 1995 } 1996 if (S->isSuperReceiver()) { 1997 ID.AddBoolean(S->isSuperReceiver()); 1998 VisitType(S->getSuperReceiverType()); 1999 } 2000 } 2001 2002 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) { 2003 VisitExpr(S); 2004 VisitDecl(S->getAtIndexMethodDecl()); 2005 VisitDecl(S->setAtIndexMethodDecl()); 2006 } 2007 2008 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) { 2009 VisitExpr(S); 2010 VisitName(S->getSelector()); 2011 VisitDecl(S->getMethodDecl()); 2012 } 2013 2014 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) { 2015 VisitExpr(S); 2016 ID.AddBoolean(S->isArrow()); 2017 } 2018 2019 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) { 2020 VisitExpr(S); 2021 ID.AddBoolean(S->getValue()); 2022 } 2023 2024 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr( 2025 const ObjCIndirectCopyRestoreExpr *S) { 2026 VisitExpr(S); 2027 ID.AddBoolean(S->shouldCopy()); 2028 } 2029 2030 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) { 2031 VisitExplicitCastExpr(S); 2032 ID.AddBoolean(S->getBridgeKind()); 2033 } 2034 2035 void StmtProfiler::VisitObjCAvailabilityCheckExpr( 2036 const ObjCAvailabilityCheckExpr *S) { 2037 VisitExpr(S); 2038 } 2039 2040 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, 2041 unsigned NumArgs) { 2042 ID.AddInteger(NumArgs); 2043 for (unsigned I = 0; I != NumArgs; ++I) 2044 VisitTemplateArgument(Args[I].getArgument()); 2045 } 2046 2047 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { 2048 // Mostly repetitive with TemplateArgument::Profile! 2049 ID.AddInteger(Arg.getKind()); 2050 switch (Arg.getKind()) { 2051 case TemplateArgument::Null: 2052 break; 2053 2054 case TemplateArgument::Type: 2055 VisitType(Arg.getAsType()); 2056 break; 2057 2058 case TemplateArgument::Template: 2059 case TemplateArgument::TemplateExpansion: 2060 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); 2061 break; 2062 2063 case TemplateArgument::Declaration: 2064 VisitDecl(Arg.getAsDecl()); 2065 break; 2066 2067 case TemplateArgument::NullPtr: 2068 VisitType(Arg.getNullPtrType()); 2069 break; 2070 2071 case TemplateArgument::Integral: 2072 Arg.getAsIntegral().Profile(ID); 2073 VisitType(Arg.getIntegralType()); 2074 break; 2075 2076 case TemplateArgument::Expression: 2077 Visit(Arg.getAsExpr()); 2078 break; 2079 2080 case TemplateArgument::Pack: 2081 for (const auto &P : Arg.pack_elements()) 2082 VisitTemplateArgument(P); 2083 break; 2084 } 2085 } 2086 2087 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2088 bool Canonical) const { 2089 StmtProfilerWithPointers Profiler(ID, Context, Canonical); 2090 Profiler.Visit(this); 2091 } 2092 2093 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID, 2094 class ODRHash &Hash) const { 2095 StmtProfilerWithoutPointers Profiler(ID, Hash); 2096 Profiler.Visit(this); 2097 } 2098