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