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