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